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 grade(50) == "Pass" | ATests were left until after the code was written, so they are likely to be shaped around the code instead of the requirements. | |
| 2tests = [(49, "Fail"), (50, "Pass")] | BThe expected result was taken from the code's own output, so the test only confirms what the code does, even if it is wrong. | |
| 3Write the expected output from the requirement, not from what your code prints | CA list of inputs and expected results written first, to be rerun each time the code grows | |
| 4Rerun every test as the code grows to catch anything a new change breaks | Dexpected = 100 - 100 * 0.1 # 10% discount rule | |
| 5expected = total(5) # copied from my code's output | Efor inp, exp in tests: print(f(inp) == exp) | |
| 6def grade(m): ... # write code, then think of tests later | FA test written from the requirement '50 or more is a Pass', ready before grade() exists |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
test first — Write test cases and expected results from the requirements before coding, so they check what the program should do, not what your code does. Rerun them as it grows.# Req: pass mark is 50 or more
assert passed(50) == True# Req: 49 fails
assert passed(49) == False# Req: 50 or more passes
assert passed(50) == True# Req: 50 or more passes
def passed(mark):
return mark >= 50tests = [(50, True), (49, False)]
for mark, expected in tests:
print(passed(mark) == expected)