Skip to main content
CodePlanet Docs

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:

RuleDetails
Whitespace trimmingLeading and trailing whitespace on each line is trimmed
Trailing newlinesExtra trailing newlines are ignored
Case sensitivityOutput comparison is case-sensitive by default
Floating pointFor problems with decimal output, a tolerance (e.g., 10⁻⁶) may be specified

Example

If the expected output is:

Hello World
42

These outputs would pass:

Hello World
42
Hello World
42

This would fail (wrong case):

hello world
42

Running Against Sample Cases

Before submitting, use the Run button to test against sample cases:

  1. Click Run (or Ctrl + Enter)
  2. The output panel shows:
    • Your actual output
    • The expected output
    • Pass/fail status for each sample case
  3. Fix any mismatches before submitting

Submission Results

After clicking Submit, you'll see results for all test cases:

StatusMeaning
AcceptedAll test cases passed
Wrong AnswerOutput doesn't match expected for one or more test cases
Time Limit ExceededCode took too long on one or more test cases
💥 Runtime ErrorCode crashed (index out of bounds, null pointer, etc.)
🔧 Compilation ErrorCode 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

  1. Extra print statements: Debug prints like print("debug") will cause wrong answers
  2. Wrong output format: Pay attention to spaces, newlines, and separators
  3. Integer overflow: In languages like C++/Java, use long long / long for large numbers
  4. Off-by-one errors: Check loop bounds carefully
  5. 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:

  1. Switch to the Custom Input tab
  2. Enter your test data
  3. Click Run
  4. Check the output matches what you expect

This is useful for testing edge cases that aren't in the sample inputs.

On this page