Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1assert calc_gst(100) == 10 | ATests the calc_gst() function alone with a fixed input of 100 and checks it returns the expected 10 | |
| 2acct.deposit(50) assert acct.balance == 150 | BThis runs the whole program through main() instead of calling the one function under test, so a failure could come from any module. | |
| 3Test a function by itself using a fixed input and a known expected output before joining it to the main program | Cassert is_adult(18) == True | |
| 4After fixing a faulty function, run the same test again to confirm the fix works and has not broken anything | Dassert average([2, 4, 6]) == 4 | |
| 5result = main() assert result == 25 | ETests one class method on its own by calling it, then checking the object's state matches the expected value | |
| 6def total(a, b): return a - b assert total(2, 3) == 5 # fixed, so no need to re-test | FThe code was changed but the test was not run again, so there is no evidence the fix works or that it has not caused new errors. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
unit testing — Testing one function or class on its own, with its own test table, before joining it to the rest of the program, so a failing test points to that module.def double(n):
return n * 2
assert double(4) == 8def area(w, h):
return w * h
assert area(3, 4) == 12acc = Account(100)
acc.withdraw(30)
assert acc.balance == 70def adult(age):
return age >= 18
assert adult(18) == Truedef cube(n):
return n ** 3
assert cube(2) == 8