Creating Test Cases With tcframe

Muhammad Salman Al Farisi
2 min readAug 22, 2022

Maybe it is unusual to hear about “test cases” for people that not into programming. Even if you are into programming, it can still be uncommon if you are not doing competitive programming.

If you are trying to solve a problem in competitive programming, you may give a complete problem statement like this:

Best Pair

Time Limit: 1 second

Memory Limit: 64 MB

Description

You are given an array A consisting of N integers. What is the maximum product (multiplication) of any pair of integers in A?

Input Format

The first line contains a single integer N. The next line contains N space-separated elements of A.

Output Format

A single line containing the maximum product.

Sample Input

4

4 -2 3 1

Sample Output

12

Constraints

  • 2 ≤ N ≤ 100,000
  • 1,000,000 ≤ A[i] ≤ 1,000,000

In this blog, I will not be focusing on how to solve that problem statement.

When you are trying to solve a problem in the leetcode, hackerrank, or maybe codeforces, have you ever thought about how the online judge will ensure all the input possibilities with a given constraint are tested?

Most of the time, the way an online judge tests a solution to a problem will not cover all the input possibilities. An online judge usually prepares a bunch of input with their expected output. When you submit your solution, the judge will give the input to your solution and check the sameness of the output of your program with the expected output. If you give different output than the expected one, you may end up with a “Wrong Answer” verdict. The input with their desired output is called “test cases”

As of my experience writing a problem in competitive programming, the hardest part is writing the test cases. Because like what I already explained, it is a task for the problem writer to make good test cases that cover all the corner cases with a good spread over the test case.

Let me introduce you to a framework for generating test cases of competitive programming problems: “tcframe”. This framework helps problem writers prepare test cases in a structured manner and ensures that the generated test cases are valid according to the specified constraints.

The most beneficial of using tcframe as your framework for building test cases is the framework using a file generator. We can copy that generator to the other to send all the test cases. Just run the generator in a different machine but still produce the same input-output even if you use a random generator in your test case!

Anyway, tcframe is based on a paper submitted to IOI conference in 2015: Introducing tcframe: A Simple and Robust Test Cases Generation Framework, written by Ashar Fuadi.

Feel free to visit the repository: https://github.com/ia-toki/tcframe

--

--