Courses / Computer Science I
Programming I

Testing Small Programs

Computer Science I 269 words Free to read

Checking That It Works

Writing code is only half the job; the other half is gaining confidence that it is correct. Testing does this by running the program on chosen inputs and comparing its actual output against the expected output you worked out independently.

A single test case is a pair: an input, and the output it should produce. A useful test suite covers three kinds of input:

The mindset is adversarial: a good tester actively tries to break the program, not to confirm it works. Passing a hundred typical cases proves little if a single overlooked edge case (an empty input, a zero, an off-by-one boundary) still crashes it.

Testing famously cannot prove a program correct — you cannot try every possible input — but a well-chosen suite can reveal the presence of bugs cheaply and repeatably. Automated tests are especially valuable because they can be re-run after every change (a regression test) to confirm nothing that used to work has broken.

Common pitfall: testing only "happy path" typical inputs and skipping edge cases. Most real bugs surface at the boundaries — an empty list, a zero, the maximum value, the first or last index. A test suite without edge cases gives false confidence; deliberately probe the boundaries.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes
Start Computer Science I free

Programming I