Test cases: input, expected output, actual output

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

Test cases: input, expected output, actual output

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which two things does a test case pair together?
A A chosen input and the output you happened to get
B A chosen input and the output you expect
2. When should you work out the expected output?
A Before running the algorithm
B After running, by copying what the algorithm printed
3. An algorithm doubles a number. For the input 7, which expected output is correct?
A 14
B 49
4. Which set of test table columns is the most useful?
A Name, Date, Colour, Size
B Input, Expected output, Actual output, Pass/Fail
5. The expected output is 20 and the actual output is 20. What is the result?
A Pass
B Fail

Match the Pairs

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

Left columnRight column
1Input: 15 | Expected: Pass | Actual: Pass AThe result is wrong because the actual output (Fail) does not match the expected output (Pass), so the result should be Fail.
2Input: 15 | Expected: Pass | Actual: Fail BInput: 72 | Expected: Pass
3Work out the expected output BEFORE running the algorithm, using the rules of the problem (e.g. a score of 50 or more is a pass). CThe actual output matched the expected output, so this test case passes.
4A test table has columns for the input, the expected output, the actual output and whether the test passed or failed. DThe actual output did not match the expected output, so this test case fails and the algorithm needs checking.
5Input: 40 | Expected: (copied from the program's output after running it) EThe expected output was taken from the program's actual output instead of being worked out beforehand, so the test cannot find mistakes.
6Input: 50 | Expected: Pass | Actual: Fail | Result: Pass F| Input | Expected | Actual | Result |

Definitions

test case

Fill in the Blanks

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

1.
Input | ________ | Actual | Result
2.
if actual _ expected then print "Pass" else print "Fail"
3.
n ← 5 expected ← n _ 2 print expected
4.
Input 7 | Expected 14 | Actual 13 | ____
5.
n ← 4 ______ ← double(n) print actual

Spot the Error

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

Question 1
A 5 <- input
B expected <- input * 2
C actual <- double(input)
D if actual = expected then
E print PASS
Question 2
A input <- 7
B expected <- addThree(input)
C actual <- addThree(input)
D if actual = expected then
E print PASS
Question 3
A Input|Expected|Actual|Result
B 4|8|8|PASS
C 6|12|10|PASS
D 9|18|18|PASS
Question 4
A Algorithm: grade(mark)
B Input: A
C Expected output: A
D Actual output: A
Question 5
A actual <- isEven(9)
B expected <- true
C if actual = expected then
D print PASS
E else
F print FAIL

Answer Key

Test cases: input, expected output, actual output
Section A: Quick Questions
Q1
B — A chosen input and the output you expect
Q2
A — Before running the algorithm
Q3
A — 14
Q4
B — Input, Expected output, Actual output, Pass/Fail
Q5
A — Pass
Section B: Match the Pairs
Q1
Input: 15 | Expected: Pass | Actual: Pass → The actual output matched the expected output, so this test case passes.
Q2
Input: 15 | Expected: Pass | Actual: Fail → The actual output did not match the expected output, so this test case fails and the algorithm needs checking.
Q3
Work out the expected output BEFORE running the algorithm, using the rules of the problem (e.g. a score of 50 or more is a pass). → Input: 72 | Expected: Pass
Q4
A test table has columns for the input, the expected output, the actual output and whether the test passed or failed. → | Input | Expected | Actual | Result |
Q5
Input: 40 | Expected: (copied from the program's output after running it) → The expected output was taken from the program's actual output instead of being worked out beforehand, so the test cannot find mistakes.
Q6
Input: 50 | Expected: Pass | Actual: Fail | Result: Pass → The result is wrong because the actual output (Fail) does not match the expected output (Pass), so the result should be Fail.
Section C: Definitions
Q1
test case — A chosen input paired with the output you expect. Run the algorithm, record the actual output, then compare: if actual matches expected it passes, otherwise it fails.
Section D: Fill in the Blanks
Q1
Input | Expected | Actual | Result
Q2
if actual = expected then print "Pass" else print "Fail"
Q3
n ← 5 expected ← n * 2 print expected
Q4
Input 7 | Expected 14 | Actual 13 | Fail
Q5
n ← 4 actual ← double(n) print actual
Section E: Spot the Error
Q1
A — Assignment goes from the value to the variable. The chosen test input should be stored with input <- 5, not 5 <- input.
Q2
B — The expected output must be worked out before running the algorithm (here input + 3). Using the algorithm to produce it means the test can never find an error.
Q3
C — The expected output (12) does not match the actual output (10), so this test case fails. The result should be FAIL.
Q4
B — The algorithm takes a mark as input, so the input should be a number such as 85. The letter A is the expected output, not the input.
Q5
B — 9 is an odd number, so the expected output of isEven(9) should be false. Working out expected output wrongly gives a misleading test result.