Tests
Test cases that run your program with a given input and check what it printed - how to write them, and what a failure is telling you.
If you want to check your code against examples - given this input, expect this output - that is what tests are. A test case is an input and the output you expect. Running the tests runs your program once per case and compares what it printed.
Writing one#
Each case has:
- What it checks - a short name, for you.
- Input (optional) - what goes to the Input tab for this case.
- Expected output - what the program should print.
Cases run one at a time and each is reported separately, so a suite of five tells you which two broke rather than that something did.
Reading a failure#
Three different things look similar and mean different things:
| What you see | What happened |
|---|---|
| It didn't compile | The program never ran. No case can pass; fix the compile error first. |
| Expected / Actual differ | It ran and printed something else. This is a real test failure. |
| Couldn't run the tests | The runner itself was unavailable. Your code is not implicated. |
What tests are for here#
They are for your program's behaviour on inputs you choose. They are not a unit-testing framework - there are no assertions inside your code and no test runner to configure.
That makes them a good fit for the thing people actually do in a project: check that a solution still handles the edge cases after a change.
Was this page helpful?