Testing Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Testing.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
Systematically running a program with known inputs to verify that its outputs are correct. Testing involves designing test cases that cover normal inputs, boundary values, and error conditions, then comparing actual results against expected results.
Try to break it before users do. Test normal cases, edge cases, and error cases.
Read the full concept explanation →How to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Testing can prove that bugs exist, but cannot prove that no bugs remain—exhaustive testing is impossible.
Common stuck point: Test edge cases: empty input, zero, maximum values, unexpected types.
Sense of Study hint: When writing test cases, cover three categories: typical inputs (normal use), boundary values (edges like 0, empty strings, maximum values), and error cases (invalid input that should be rejected gracefully). For each test, define the input, the expected output, and compare it to the actual output.
Common Mistakes to Watch For
Before you work through the examples, skim the mistake guide so you know which shortcuts and sign errors to avoid.
Worked Examples
Example 1
easyAnswer
First step
Full solution
- 2 Step 2: Boundary test: isEven(0) should return TRUE. Zero is an edge case that is technically even.
- 3 Step 3: Erroneous test: isEven('hello') should handle the invalid input gracefully (return an error or FALSE). This tests that the function does not crash on bad input.
Example 2
mediumExample 3
mediumExample 4
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
mediumExample 2
hardExample 3
easyExample 4
easyExample 5
easyExample 6
easyExample 7
easyExample 8
easyExample 9
easyExample 10
easyExample 11
mediumExample 12
mediumExample 13
mediumExample 14
mediumExample 15
mediumExample 16
mediumExample 17
mediumExample 18
mediumExample 19
mediumExample 20
challengeExample 21
challengeExample 22
challengeExample 23
easyExample 24
easyExample 25
easyExample 26
easyExample 27
mediumExample 28
mediumExample 29
mediumExample 30
mediumExample 31
mediumExample 32
mediumExample 33
mediumExample 34
mediumExample 35
mediumExample 36
mediumExample 37
hardExample 38
hardExample 39
hardExample 40
hardExample 41
challengeExample 42
challengeRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.