Practice Testing in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick 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.

Showing a random 20 of 50 problems.

Example 1

medium
A function factorial(n)\text{factorial}(n) accepts nโ‰ฅ0n \ge 0. Which input is the boundary value with 00 multiplications?

Example 2

easy
A test expects 4242 but the function returns 2424. Pass or fail?

Example 3

medium
What is the term for an automated test that runs at every commit to catch regressions?

Example 4

medium
A regression test is added after a bug is fixed. What is its purpose?

Example 5

challenge
You have a function over the integer range 0..1000. You cannot test all 1001 values. Justify testing 0, 1, 500, 999, 1000 specifically.

Example 6

medium
A function adds 1 to its input. Test cases: input 0->1, input -1->0, input 5->6. How many test cases, and do they pass if the function is correct?

Example 7

medium
A test suite covers inputs 1, 2, 3 but a bug only appears at input 1000. What does this illustrate about testing?

Example 8

medium
A function should return the max of a list. Choose a good edge-case input that often breaks naive implementations.

Example 9

hard
Explain the difference between white-box and black-box testing. Which approach would you use to test a sorting function, and why?

Example 10

easy
A test gives input 3 and expects output 9 (square). The function returns 9. Does the test pass?

Example 11

medium
Two test cases share a long setup. A developer extracts the setup into a helper function. Which test-quality property does this preserve?

Example 12

challenge
A program processes a list and is tested only on lists of length โ‰ค10\le 10. A bug appears only when length โ‰ฅ216\ge 2^{16}. Why did testing miss it, and name a strategy that would have caught it.

Example 13

medium
A password validation function requires: at least 8 characters, at least one uppercase letter, and at least one digit. Design test cases that check each requirement independently.

Example 14

hard
A team uses code coverage to measure tests. The coverage is 100%100\%, but a critical bug still ships. How is this possible?

Example 15

easy
A test that checks the smallest or largest legal input is called a ____ test.

Example 16

hard
A function search(L,k)\text{search}(L, k) returns the index of kk in list LL or โˆ’1-1. Design tests covering: empty list, first element, last element, missing element, duplicates.

Example 17

easy
For a function valid on ages 0 to 120, name one boundary value to test.

Example 18

easy
Which input type catches bugs at the limits of allowed values: normal, boundary, or error?

Example 19

easy
For a function valid on inputs 1โ‰คnโ‰ค501 \le n \le 50, name an erroneous (out-of-range) input to test.

Example 20

medium
A function `isEven(n)` is tested with 2->true, 3->false, 0->true. The code returns true for 0. Pass or fail on the 0 case?