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 | |
|---|---|---|
| 1Make this function faster and keep the same output | AA prompt asking an AI tool for a more efficient version while requiring that behaviour stays unchanged | |
| 2assert total_cost(3, 2.5) == 7.5 | BIf any result changes, the optimised code has broken behaviour and the change must be rejected or fixed, even if it is faster. | |
| 3Compare before and after: both versions must give the same result for the same input | CA test case run on both the original and optimised code to check the result is identical | |
| 4Re-run the same test cases on the optimised code to prove it still works | DShorter or cleaner code is not proof it works. The optimised code must be re-tested with the same test cases before it is accepted. | |
| 5The AI version looks shorter, so I will keep it without testing. | Eprint(old_total(data) == new_total(data)) | |
| 6Test 4 now fails on the AI version, but it runs faster, so I will keep it. | Ffor t in tests: assert new_total(t[0]) == t[1] |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
regression test — Re-running the same test cases on AI-optimised code to prove it still gives identical results as before. If any result changes, reject the change.assert newAvg(data) == oldAvg(data)assert sumNew([1, 2, 3]) == 6if newResult != oldResult:
print("Reject the change")for x in tests:
assert fast(x) == slow(x)def totalFast(numbers):
return sum(numbers)