Skip to main content

Overview

The check command validates your solution using a custom checker script instead of direct output comparison. This is essential for problems where multiple correct answers exist, making simple string comparison inadequate.
Use check when a problem accepts multiple valid solutions (e.g., “find any valid pair”, “output any permutation that satisfies”, etc.)

Basic Usage

quicktest check --target-file=main.cpp --checker-file=checker.cpp --gen-file=gen.cpp
Or using the shorter alias:
qt check -t main.cpp -c checker.cpp -g gen.cpp

Required Parameters

target-file
string
required
Your solution file to validate. Can be any supported language (C++, Java, Python, Rust, Go, C, Kotlin).Short form: -t
--target-file=main.cpp
-t main.cpp
checker-file
string
required
The checker script that validates whether the solution’s output is correct. This script receives the input and your solution’s output, then outputs “YES” or “NO”.Short form: -c
--checker-file=checker.cpp
-c checker.cpp
gen-file
string
required
Random test case generator file.Short form: -gDefault: "" (empty - can use --prefix instead)
The generator and prefix options are mutually exclusive. Use either --gen-file for random generation or --prefix to run existing test cases.
--gen-file=gen.cpp
-g gen.cpp

Optional Parameters

test-cases
number
default:"1000"
Number of test cases to generate and run.Alias: --tc
--test-cases=500
--tc 500
timeout
number
default:"2000"
Maximum execution time per test case in milliseconds.Alias: --tout
--timeout=1000
--tout 1000
memory-limit
number
default:"1000000000"
Memory limit in bytes (default is 1GB).Alias: --ml
--memory-limit=512000000
--ml 512000000
prefix
string
default:""
Path prefix for existing test case files.Short form: -pConflicts with: --gen-file
--prefix=test_cases/testcase
-p test_cases/testcase

Control Flags

break_bad
boolean
default:"false"
Stop execution immediately when a WA (Wrong Answer), TLE (Time Limit Exceeded), or RTE (Runtime Error) occurs.Aliases: --break, -b
The check command uses --break_bad (with underscore) unlike other commands which use --break-bad (with hyphen). This is a quirk in the source code.
--break_bad
--break
-b

Save Options

The --save-all and --save-bad flags are mutually exclusive.
save-bad
boolean
default:"false"
Save only test cases that fail (WA, TLE, RTE, MLE states).
--save-bad
save-all
boolean
default:"false"
Save all test cases regardless of their result.
--save-all

Run Filters

Use these flags to run specific subsets of previously saved test cases:
run-all
boolean
default:"false"
Run all saved test cases.
run-ac
boolean
default:"false"
Run only test cases that previously passed (Accepted status).
run-wa
boolean
default:"false"
Run only test cases that previously failed with Wrong Answer.
run-tle
boolean
default:"false"
Run only test cases that previously exceeded time limit.
run-mle
boolean
default:"false"
Run only test cases that previously exceeded memory limit.
run-rte
boolean
default:"false"
Run only test cases that previously had runtime errors.

How Checkers Work

A checker script must:
  1. Read the original input (typically from .qt/input.txt)
  2. Read your solution’s output from stdin
  3. Validate the output meets problem constraints
  4. Output “YES” if valid, “NO” otherwise

Examples

Basic Checker Test

qt check -t main.cpp -c checker.cpp -g gen.cpp --tc 500 --tout 1000

Multiplication Problem Example

Problem: Given n, output two numbers that multiply to n.
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;
    
    // One valid solution
    cout << 1 << " " << n << "\n";
    
    return 0;
}
Run the test:
qt check -t main.cpp -c checker.cpp -g gen.cpp --tc 500 --tout 1000

Debug Failed Validations

1

Run with save-bad flag

Save test cases where the checker returns NO:
qt check -t main.cpp -c checker.cpp -g gen.cpp --tc 50 --tout 1000 --save-bad
2

Manually inspect saved cases

Check the saved test case files to understand what inputs cause failures.
3

Re-run failed cases

After fixing, test only the previously failing cases:
qt check -t main.cpp -c checker.cpp -g gen.cpp --run-wa

Graph Problem Example

Problem: Output any valid Hamiltonian path in a graph (many solutions exist).
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Read graph from input file
    ifstream in(".qt/input.txt");
    int n, m;
    in >> n >> m;
    
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        in >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    // Read solution's path
    vector<int> path(n);
    for (int i = 0; i < n; i++) {
        cin >> path[i];
    }
    
    // Validate:
    // 1. All nodes visited exactly once
    set<int> visited(path.begin(), path.end());
    if (visited.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    
    // 2. Each consecutive pair has an edge
    for (int i = 0; i < n - 1; i++) {
        int u = path[i], v = path[i + 1];
        if (find(adj[u].begin(), adj[u].end(), v) == adj[u].end()) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}

Using Existing Test Cases

qt check -t main.cpp -c checker.cpp -p test_cases/testcase --tc 10

Save All for Analysis

Save all test cases to study the variety of valid solutions:
qt check -t main.cpp -c checker.cpp -g gen.cpp --tc 100 --save-all

Checker Best Practices

Be thorough: Check all problem constraints, not just the obvious ones. Include bounds checking, uniqueness, and structural requirements.
Handle edge cases: Ensure your checker handles empty outputs, invalid formats, and boundary values gracefully.
Output only YES/NO: Keep checker output simple. Don’t add debugging information that could confuse QuickTest.
Read from the correct file: QuickTest saves input to .qt/input.txt. Always read from this file, not stdin.

Common Use Cases

Multiple Valid Answers

Problems asking for “any” valid solution

Approximate Solutions

Answers within an epsilon tolerance

Construction Problems

Build any structure meeting criteria

Permutation Problems

Any valid ordering or arrangement

Understanding Test Results

QuickTest displays real-time results:
  • AC - Accepted (checker returned YES)
  • WA - Wrong Answer (checker returned NO)
  • TLE - Time Limit Exceeded
  • MLE - Memory Limit Exceeded
  • RTE - Runtime Error

Tips

Test your checker separately: Before using it with QuickTest, manually test your checker with known valid and invalid outputs.
Use —break_bad for debugging: Stop at the first failure to investigate the issue immediately.
Start with a simple checker: Build a basic checker first, verify it works, then add more sophisticated validation.

See Also

  • cmp - Compare against a correct solution (for single-answer problems)
  • stress - Test for time/memory limits only
  • output - Generate output files from test cases

Build docs developers (and LLMs) love