Testing a prototype for accuracy

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

Testing a prototype for accuracy

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is the correct way to get the expected result in an accuracy test?
A Work it out by hand from known input data before running the prototype
B Copy whatever the prototype outputs and call it expected
2. A weather API sends 22.0 degrees Celsius. Your prototype should display Fahrenheit. Which expected value is worked out by hand correctly?
A 54.0 (22 x 9 / 5 - 32 + 32 - 22 + 54)
B 71.6 (22 x 9 / 5 + 32)
3. The prototype receives a price of 4.995 and displays 5.00 when the spec says to round to 2 decimal places. What does the test show?
A It matches only if the hand-calculated expected value is 5.00 under the stated rounding rule
B It always fails because the numbers are different
4. Test data: 3 items at $2.50 each with 10% GST added. Which expected total should you record?
A $7.75
B $8.25
5. Which check compares received vs displayed data?
A Compare the value in the API response with the value shown on screen
B Check that the screen layout looks neat

Match the Pairs

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

Left columnRight column
1assert round(c * 9 / 5 + 32, 1) == 98.6 AThe expected result was worked out wrongly. 100 plus 10% GST should be 110.0, so the test checks against the wrong value.
2print(received == displayed) BThe expected value is produced by the program itself, not worked out by hand, so the test always passes and proves nothing.
3Work out the expected value by hand first (3 items at 4.50 = 13.50), then compare it with the program's total CCompares the data received from the API with the data shown on screen to see if it changed on the way
4A rounding error appears when the output differs from the expected value, for example 2.5 shown as 2 DChecks the converted temperature matches the answer worked out by hand for a known input of 37 degrees Celsius
5expected = average([70, 80, 90]) assert average([70, 80, 90]) == expected Eexpected = 13.50 actual = total_cost(3, 4.50) print(actual == expected)
6assert price_with_gst(100) == 10.0 Fprint(int(2.5), round(2.5, 1))

Definitions

accuracy testing

Fill in the Blanks

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

1.
expected = 59.97 actual = round(19.99 * 3, 2) print(actual __ expected)
2.
total = 10 / 3 shown = _____(total, 2) print(shown)
3.
expected = 212 actual = 100 _ 9 / 5 + 32 print(actual == expected)
4.
received = 42.5 displayed = float("42.5") print("Mismatch:", received __ displayed)
5.
expected = 59.97 actual = 19.99 * 3 print(___(actual - expected) < 0.01)

Spot the Error

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

Question 1
A celsius = 25
B expected = 77.0
C actual = celsius * 5 / 9 + 32
D print(actual == expected)
Question 2
A price = 19.999
B expected = 20.0
C shown = int(price)
D print(shown == expected)
Question 3
A marks = [80, 70, 90]
B expected = 240
C avg = sum(marks) / len(marks)
D print(avg == expected)
Question 4
A received = {'temp': 21.5}
B shown = received['temp']
C assert shown == 215
Question 5
A km = 12.5
B miles = km * 0.621371
C want = 7.77
D print(round(miles, 1) == want)

Answer Key

Testing a prototype for accuracy
Section A: Quick Questions
Q1
A — Work it out by hand from known input data before running the prototype
Q2
B — 71.6 (22 x 9 / 5 + 32)
Q3
A — It matches only if the hand-calculated expected value is 5.00 under the stated rounding rule
Q4
B — $8.25
Q5
A — Compare the value in the API response with the value shown on screen
Section B: Match the Pairs
Q1
assert round(c * 9 / 5 + 32, 1) == 98.6 → Checks the converted temperature matches the answer worked out by hand for a known input of 37 degrees Celsius
Q2
print(received == displayed) → Compares the data received from the API with the data shown on screen to see if it changed on the way
Q3
Work out the expected value by hand first (3 items at 4.50 = 13.50), then compare it with the program's total → expected = 13.50 actual = total_cost(3, 4.50) print(actual == expected)
Q4
A rounding error appears when the output differs from the expected value, for example 2.5 shown as 2 → print(int(2.5), round(2.5, 1))
Q5
expected = average([70, 80, 90]) assert average([70, 80, 90]) == expected → The expected value is produced by the program itself, not worked out by hand, so the test always passes and proves nothing.
Q6
assert price_with_gst(100) == 10.0 → The expected result was worked out wrongly. 100 plus 10% GST should be 110.0, so the test checks against the wrong value.
Section C: Definitions
Q1
accuracy testing — Comparing the prototype's actual output with expected results worked out by hand from known data, to find wrong values such as rounding or conversion errors.
Section D: Fill in the Blanks
Q1
expected = 59.97 actual = round(19.99 * 3, 2) print(actual == expected)
Q2
total = 10 / 3 shown = round(total, 2) print(shown)
Q3
expected = 212 actual = 100 * 9 / 5 + 32 print(actual == expected)
Q4
received = 42.5 displayed = float("42.5") print("Mismatch:", received != displayed)
Q5
expected = 59.97 actual = 19.99 * 3 print(abs(actual - expected) < 0.01)
Section E: Spot the Error
Q1
C — The conversion formula is upside down. By hand, 25 * 9 / 5 + 32 = 77.0, but 5 / 9 gives about 45. The test would fail because of a formula error, so the line should be celsius * 9 / 5 + 32.
Q2
C — int() truncates 19.999 to 19 instead of rounding it. The hand-calculated expected value is 20.0, so the prototype must round with round(price, 1).
Q3
B — The hand calculation is wrong. The total is 240, but the average needs 240 / 3 = 80. An incorrect expected value makes the accuracy test meaningless.
Q4
C — The received data says 21.5, so the displayed value must be compared with 21.5. Writing 215 drops the decimal point and would wrongly report a display error.
Q5
D — By hand, 12.5 * 0.621371 = 7.7671, which is 7.77 to 2 decimal places. Rounding to 1 place gives 7.8, so the comparison fails. It should be round(miles, 2).