Skip to main content
Learn how to use Quick Test CLI effectively with practical examples from real competitive programming scenarios.

Compare mode (cmp)

Compare your optimized solution against a brute-force correct solution.

Maximum subarray problem

This example demonstrates finding the maximum sum of a contiguous subarray using Kadane’s algorithm.
1

Create the generator

gen.cpp
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
    // Generator for Maximum Subarray Problem
    int seed = stoi(string(argv[1]));
    srand(seed);

    const int N = int(1e3);
    const int Ai = int(1e5);

    int n = rand() % N + 1;
    cout << n << "\n";

    default_random_engine generator;
    uniform_int_distribution<int> distribution(-Ai, Ai);

    for(int i = 0; i < n; i++) {
        if(i > 0) cout << " ";
        cout << distribution(generator);
    }
    return 0;
}
The generator creates arrays of random size with positive and negative numbers.
2

Write the brute-force solution

correct.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Maximum Subarray Problem - O(n²) brute force
    int n; cin >> n;
    vector<int> values(n);
    for(int &a: values)
        cin >> a;
    
    int best = 0;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = i; j < n; j++) {
            sum += values[j];
            best = max(best, sum);
        }
    }
    cout << best << "\n";
    return 0;
}
This O(n²) solution is slow but guaranteed correct.
3

Write the optimized solution (with bug)

main.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Maximum Subarray Problem - O(n) with intentional bug
    int n; cin >> n;
    vector<int> values(n);
    for(int &a: values)
        cin >> a;
    
    int best = 0, sum = 0;
    
    // Bug: i+1 < n instead of i < n
    for (int i = 0; i+1 < n; i++) {
        sum = max(values[i], sum + values[i]);
        best = max(best, sum);
    }
    cout << best << "\n";
    return 0;
}
This solution has a bug that will be caught by stress testing.
4

Run the stress test

qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 500 --tout 1000 --save-bad --break
Quick Test will find the bug and save the failing test case.
Use --break to stop immediately when a failure is found, then examine the saved test case.

Multi-language examples

# Navigate to examples
cd examples/cmp/cpp

# Run with full options
quicktest cmp --target-file=main.cpp --correct-file=correct.cpp --gen-file=gen.cpp --test-cases=500 --timeout=1000

# Short form
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 500 --tout 1000

Stress mode

Test your solution for time limit issues without comparing against a correct solution.

When to use stress mode

  • You’re confident about correctness but want to test performance
  • You don’t have a brute-force solution
  • You want to find the worst-case input quickly
cd examples/stress/cpp
qt stress -t main.cpp -g gen.cpp --tc 15 --tout 1000

Check mode

Use a custom checker for problems with multiple valid answers.

Factorization problem

Problem: Given n, output two numbers that multiply to n.
1

Write the checker

checker.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Checker validates that x * y == n
    
    // Read n from input file
    ifstream in (".qt/input.txt");
    int n; in >> n;

    // Read answer from target program's output
    int x, y;
    cin >> x >> y;

    // Validate the answer
    cout << (x*y == n ? "YES" : "NO") << endl;
    
    return 0;
}
The checker reads the input from .qt/input.txt and validates the solution’s output.
2

Create the generator

gen.cpp
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
    int seed = stoi(string(argv[1]));
    srand(seed);

    // Generate a random number
    int n = rand() % 1000 + 1;
    cout << n << "\n";
    
    return 0;
}
3

Write the solution

main.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;
    
    // Find two factors (many valid answers exist)
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            cout << i << " " << n/i << "\n";
            return 0;
        }
    }
    
    // n is prime
    cout << 1 << " " << n << "\n";
    return 0;
}
4

Run with checker

cd examples/check/cpp
qt check -t main.cpp -c checker.cpp -g gen.cpp --tc 500 --tout 1000
The checker must output “YES” for correct answers and “NO” for incorrect answers.

Output mode

Run your solution against pre-made test cases and optionally save outputs.

Using static test files

1

Prepare test cases

Create test files with a common prefix:
test_cases/
├── testcase_ac_01.txt
├── testcase_ac_02.txt
└── testcase_ac_03.txt
Each file contains one test case input.
2

Run against test cases

qt output -t cpp/main.cpp -p test_cases/testcase_ac
This displays outputs in the terminal.
cd examples/output
qt output -t cpp/main.cpp -p test_cases/testcase_ac --save-out

Real contest workflow

Here’s a typical workflow during a competitive programming contest:
1

Initial setup

mkdir problem-a
cd problem-a
touch main.cpp gen.cpp correct.cpp
2

Write and test brute force

# Write correct.cpp (brute force solution)
# Test with sample inputs first
qt output -t correct.cpp -p samples/input
3

Develop optimized solution

# Write main.cpp (optimized solution)
# Write gen.cpp (random test generator)

# Quick test with few cases
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 50 --break
4

Comprehensive testing

# If quick test passes, run more thorough tests
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 1000 --save-bad --break
5

Debug if needed

# If failures found, check saved test case
cat .qt/testcases/testcase_wa_001.txt

# Fix bug, then re-test failed cases
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --run-wa
6

Final validation

# Test with official samples
qt output -t main.cpp -p samples/input

# One more stress test
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 2000 --break
7

Submit

You’re ready to submit main.cpp to the judge!

Advanced patterns

Finding worst-case input

# Save all test cases
qt stress -t main.cpp -g gen.cpp --tc 1000 --save-all

# Analyze which inputs cause slowest execution
# Check .qt/testcases/ for patterns

Testing edge cases

# Create edge case test files manually
echo "1\n0" > test_cases/edge_01.txt
echo "100000\n1 2 3 ..." > test_cases/edge_02.txt

# Test against edge cases
qt cmp -t main.cpp -c correct.cpp -p test_cases/edge

Batch testing multiple solutions

# Test solution v1
qt cmp -t main_v1.cpp -c correct.cpp -g gen.cpp --tc 500

# Test solution v2
qt cmp -t main_v2.cpp -c correct.cpp -g gen.cpp --tc 500

# Compare performance

Interactive debugging

# Run with --diff to see exact differences
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --diff --break

# When it stops, check the input/output
cat .qt/input.txt
cat .qt/output.txt

# Debug with your solution
gdb .qt/main < .qt/input.txt

Tips and best practices

Begin with a small number of test cases (--tc 10) to verify everything works, then increase:
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 10
# If pass, increase
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 100
# Finally
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 1000
Stop immediately on first failure to debug quickly:
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --break --save-bad
  • For fast problems: --tout 500
  • For standard problems: --tout 1000 or --tout 2000
  • For Python/interpreted languages: increase by 2-3x
Your generator should:
  • Accept a seed argument
  • Generate valid inputs only
  • Cover edge cases (min/max values, empty inputs)
Always run a final stress test before submitting:
qt cmp -t main.cpp -c correct.cpp -g gen.cpp --tc 2000 --break

Next steps

CLI Reference

View all available commands and options

Troubleshooting

Fix common issues

Build docs developers (and LLMs) love