Test File Format Specification¶
Status: Canonical Reference
Created: 2026-01-02
Related: migration-plan.md
This document defines the data contract for .in and .out test files.
Design Principles¶
- Human-readable first: Files should be reviewable without running code
- Signature-aligned: Input mirrors function parameters
- Self-contained: Output contains all verification data
- Runner-agnostic: Format doesn't dictate validation logic
Input Format (.in files)¶
Rule¶
One line per parameter, following function signature order.
Each line contains a JSON-serializable value.
Example¶
Why This Format¶
| Benefit | Explanation |
|---|---|
| Decoupled from names | Runner uses positional args, doesn't parse nums = ... |
| Diff-friendly | One parameter per line = easy to spot changes |
| Scalable | Works for any number of parameters |
| Simple | lines[i] β json.loads() β argument |
Non-examples¶
β Single JSON object
Reason: Couples format to parameter namesβ Concatenated line
Reason: Loses structural clarity, ambiguous parsingβ Variable assignment
Reason: Requires parsing variable namesOutput Format (.out files)¶
Rule¶
One line per validation value, in verification order.
First line is always the return value (if any).
Subsequent lines represent modified state (if needed).
Category A: Simple Return Value¶
For problems that only return a value without side effects.
Category B: Multi-output Validation¶
For problems with in-place modification + return value.
LeetCode validates both: 1. The return value is correct 2. The modified array is correct
Both must be specified for human review.
LeetCode shows: Output: 2, nums = [2,2,_,_]
Category C: Custom Judge Required¶
Same format as A or B, but runner uses JUDGE_FUNC for semantic comparison.
When to use: - Order-independent results (e.g., permutations) - Floating-point comparison with tolerance - Multiple valid answers
Problem Classification¶
| Category | Description | Output Lines | Example |
|---|---|---|---|
| A | Simple return value | 1 | Two Sum |
| B | In-place + return value | 2+ | Remove Element |
| C | Custom judge needed | 1 or 2+ | 3Sum |
Category B Problems (Multi-output)¶
| Problem | Return | Verification |
|---|---|---|
| 0026_remove_duplicates | k | nums[:k] |
| 0027_remove_element | k | nums[:k] |
| 0080_remove_duplicates_ii | k | nums[:k] |
Category A Problems (Single-output, in-place no return)¶
| Problem | Output |
|---|---|
| 0075_sort_colors | nums |
| 0088_merge_sorted_array | nums1 |
| 0283_move_zeroes | nums |
Canonical Format Rules¶
JSON Literal Requirements¶
| Type | Format | Example |
|---|---|---|
| Integer | JSON number | 42 |
| Float | JSON number | 3.14159 |
| Boolean | JSON lowercase | true, false |
| String | JSON double-quoted | "abc" |
| Array (1D) | JSON array, no spaces | [2,7,11,15] |
| Array (2D) | JSON array, single line | [[1,2],[3,4]] |
| Null | JSON null | null |
Normalization¶
| Rule | Specification |
|---|---|
| Quotes | Always ", never ' |
| Spaces | No spaces after : or , |
| Booleans | true/false (not True/False) |
| Line endings | \n (parser tolerates \r\n) |
| Trailing newline | Optional |
| Empty files | Not allowed |
Anti-patterns¶
β Don't merge return + side effects into JSON¶
Reason: Invents a new format per problem. Not human-readable.
β Don't omit validation data¶
Reason: Cannot verify correctness without running code.
β Don't use comments for data¶
Reason: Comments aren't machine-parseable.
β Don't use Python format¶
Edge Cases¶
Empty Arrays¶
Single Element¶
Empty String¶
Validation¶
Gate 0: Format Validation¶
All test files must pass:
Checks: - Each line is valid JSON - No empty files - No BOM - Correct line endings
Gate 1: Behavioral Validation¶
All tests must pass with handwritten solve():
Related Documents¶
| Document | Purpose |
|---|---|
| specification.md | Feature specification |
| migration-plan.md | Migration execution guide |
| solution-contract.md | solve() function requirements |
| generator-contract.md | Generator output requirements |