Test Cases
Understanding problem tests
Understanding how test cases work on CodePlanet is essential for writing correct solutions and debugging failures.
How Test Cases Work
Every problem on CodePlanet comes with a set of test cases. Each test case defines:
- Input: The data your program receives via stdin
- Expected Output: The exact output your program should produce
When you submit a solution, your code is executed once for each test case. The actual output is compared against the expected output to determine pass/fail.
Test Case Types
Sample Test Cases (Visible)
These are shown in the problem description. You can see both the input and expected output. Use these to:
- Understand the problem requirements
- Verify your basic approach
- Debug using concrete examples
Hidden Test Cases
These test your solution more thoroughly and are not visible to you. They typically include:
- Edge cases: Empty inputs, single elements, minimum/maximum values
- Boundary conditions: Values at the limits of constraints
- Large inputs: Stress tests for time and memory limits
- Special patterns: Sorted arrays, all-same elements, worst-case scenarios
Output Comparison Rules
CodePlanet uses the following rules when comparing your output to the expected output:
| Rule | Details |
|---|---|
| Whitespace trimming | Leading and trailing whitespace on each line is trimmed |
| Trailing newlines | Extra trailing newlines are ignored |
| Case sensitivity | Output comparison is case-sensitive by default |
| Floating point | For problems with decimal output, a tolerance (e.g., 10⁻⁶) may be specified |
Example
If the expected output is:
These outputs would pass:
This would fail (wrong case):
Running Against Sample Cases
Before submitting, use the Run button to test against sample cases:
- Click Run (or
Ctrl + Enter) - The output panel shows:
- Your actual output
- The expected output
- Pass/fail status for each sample case
- Fix any mismatches before submitting
Submission Results
After clicking Submit, you'll see results for all test cases:
| Status | Meaning |
|---|---|
| ✅ Accepted | All test cases passed |
| ❌ Wrong Answer | Output doesn't match expected for one or more test cases |
| ⏱ Time Limit Exceeded | Code took too long on one or more test cases |
| 💥 Runtime Error | Code crashed (index out of bounds, null pointer, etc.) |
| 🔧 Compilation Error | Code failed to compile (syntax errors) |
Partial Results
For each test case, you can see:
- Status: Pass or fail
- Runtime: Execution time in milliseconds
- Memory: Memory usage in MB
- Input (for sample cases): The test input that was used
- Your output vs Expected output (for sample cases only)
Writing Good Solutions
Common Pitfalls
- Extra print statements: Debug prints like
print("debug")will cause wrong answers - Wrong output format: Pay attention to spaces, newlines, and separators
- Integer overflow: In languages like C++/Java, use
long long/longfor large numbers - Off-by-one errors: Check loop bounds carefully
- Hardcoding sample output: Your code must work for ALL test cases, not just samples
Debugging Tips
- Start with sample cases: Make sure these pass before submitting
- Add your own test cases: Think about edge cases not in the samples
- Read constraints carefully: They tell you the input size and expected complexity
- Check for special cases: What happens with n=0? n=1? All elements equal?
Custom Test Input
You can provide your own test input in the Input panel:
- Switch to the Custom Input tab
- Enter your test data
- Click Run
- Check the output matches what you expect
This is useful for testing edge cases that aren't in the sample inputs.