Judging whether a set of test cases is enough

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Judging whether a set of test cases is enough

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A program checks if a mark is 0 to 100. A student tests only 50, 60 and 75. Is this test set enough?
A Yes, three tests is plenty
B No, it only has normal data
2. Which checklist makes a test set complete for a range check?
A Normal, boundary and invalid data
B Three different normal values
3. Code has if score >= 50: print('Pass') else: print('Fail'). Tests used: 70, 85, 90. What is missing?
A A test that runs the else branch
B Nothing, all the tests passed
4. A loop runs from 1 to 10. Which test set covers the loop better?
A Zero, one and many repeats
B Only many repeats every time
5. All 8 of your test cases passed. What can you correctly conclude?
A The program has no bugs at all
B No bugs were found by these tests

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1tests = [15, 18, 17] # age check: >= 18 Aif mark >= 50: print('Pass') else: print('Fail') # tests: 80, 90
2tests = [25, 18, 17, -5, 'abc'] BStronger test set: normal (25), boundary (18 and 17) and invalid (-5, 'abc') data are all included
3An untested branch leaves the program partly validated: every if and else path needs at least one test that runs it CWeak test set: no invalid data (like -5 or 'abc') and only one value on the boundary side, so it is not enough yet
4Passing tests do not prove there are no bugs: a loop that is never run with an empty list could still hide an error DFive normal values were all passed, but there is no boundary or invalid data. Passing tests never prove the program has no bugs.
5# Tests: 5, 10, 20, 30, 40 # All passed, so the program is fully tested! Etotal = 0 for n in nums: total = total + n # tested with [1, 2, 3] only
6while count < 3: count = count + 1 # Test plan: skip the loop, run once FThe test plan never runs the loop several times, so the loop is untested and the code is only partly validated.

Definitions

test coverage

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
normal = [40, 75] boundary = [0, 100] _______ = [-5, 101]
2.
if mark >= 50: print("Pass") ____: print("Fail")
3.
assert grade(50) == "Pass" assert grade(__) == "Fail"
4.
passed = 9 total = 10 print(passed _ total)
5.
___ score in scores: count = count + 1 print(count)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A tests = [50, 0, 100, -1]
B count = 0
C for t in test:
D count = count + 1
Question 2
A grade = 55
B if grade >= 50
C print("Pass")
D else:
E print("Fail")
Question 3
A def grade(m):
B if m => 50:
C return "Pass"
D return "Fail"
E assert grade(50) == "Pass"
F assert grade(49) == "Fail"
Question 4
A tests = [(50, 1), (49, 0)
B for mark, want in tests:
C got = int(mark >= 50)
D print(got == want)
Question 5
A have = ["norm", "edge")
B need = ["norm", "edge", "bad"]
C for n in need:
D if n not in have:
E print("Missing", n)

Answer Key

Judging whether a set of test cases is enough
Section A: Quick Questions
Q1
B — No, it only has normal data
Q2
A — Normal, boundary and invalid data
Q3
A — A test that runs the else branch
Q4
A — Zero, one and many repeats
Q5
B — No bugs were found by these tests
Section B: Match the Pairs
Q1
tests = [15, 18, 17] # age check: >= 18 → Weak test set: no invalid data (like -5 or 'abc') and only one value on the boundary side, so it is not enough yet
Q2
tests = [25, 18, 17, -5, 'abc'] → Stronger test set: normal (25), boundary (18 and 17) and invalid (-5, 'abc') data are all included
Q3
An untested branch leaves the program partly validated: every if and else path needs at least one test that runs it → if mark >= 50: print('Pass') else: print('Fail') # tests: 80, 90
Q4
Passing tests do not prove there are no bugs: a loop that is never run with an empty list could still hide an error → total = 0 for n in nums: total = total + n # tested with [1, 2, 3] only
Q5
# Tests: 5, 10, 20, 30, 40 # All passed, so the program is fully tested! → Five normal values were all passed, but there is no boundary or invalid data. Passing tests never prove the program has no bugs.
Q6
while count < 3: count = count + 1 # Test plan: skip the loop, run once → The test plan never runs the loop several times, so the loop is untested and the code is only partly validated.
Section C: Definitions
Q1
test coverage — Test cases are enough when they use normal, boundary and invalid data and run every branch and loop. Missing any leaves the program only partly validated, and passing tests never prove no bugs.
Section D: Fill in the Blanks
Q1
normal = [40, 75] boundary = [0, 100] invalid = [-5, 101]
Q2
if mark >= 50: print("Pass") else: print("Fail")
Q3
assert grade(50) == "Pass" assert grade(49) == "Fail"
Q4
passed = 9 total = 10 print(passed < total)
Q5
for score in scores: count = count + 1 print(count)
Section E: Spot the Error
Q1
C — The list is called tests, not test. Using test causes a NameError, so no test data is looped over. It should be for t in tests:.
Q2
B — An if statement must end with a colon. Without it Python gives a SyntaxError, so neither branch can be tested. It should be if grade >= 50:.
Q3
B — The operator => does not exist in Python. The boundary test needs >=, so the line should be if m >= 50:.
Q4
A — The list is missing its closing square bracket, which causes a SyntaxError. It should end with )].
Q5
A — The list opens with [ but closes with ), a mismatched bracket that causes a SyntaxError. It should end with ].