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
mediumA function accepts . Which input is the boundary value with multiplications?
Example 2
easyA test expects but the function returns . Pass or fail?
Example 3
mediumWhat is the term for an automated test that runs at every commit to catch regressions?
Example 4
mediumA regression test is added after a bug is fixed. What is its purpose?
Example 5
challengeYou 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
mediumA 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
mediumA test suite covers inputs 1, 2, 3 but a bug only appears at input 1000. What does this illustrate about testing?
Example 8
mediumA function should return the max of a list. Choose a good edge-case input that often breaks naive implementations.
Example 9
hardExplain the difference between white-box and black-box testing. Which approach would you use to test a sorting function, and why?
Example 10
easyA test gives input 3 and expects output 9 (square). The function returns 9. Does the test pass?
Example 11
mediumTwo test cases share a long setup. A developer extracts the setup into a helper function. Which test-quality property does this preserve?
Example 12
challengeA program processes a list and is tested only on lists of length . A bug appears only when length . Why did testing miss it, and name a strategy that would have caught it.
Example 13
mediumA 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
hardA team uses code coverage to measure tests. The coverage is , but a critical bug still ships. How is this possible?
Example 15
easyA test that checks the smallest or largest legal input is called a ____ test.
Example 16
hardA function returns the index of in list or . Design tests covering: empty list, first element, last element, missing element, duplicates.
Example 17
easyFor a function valid on ages 0 to 120, name one boundary value to test.
Example 18
easyWhich input type catches bugs at the limits of allowed values: normal, boundary, or error?
Example 19
easyFor a function valid on inputs , name an erroneous (out-of-range) input to test.
Example 20
mediumA 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?