Testing a visual program

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

Testing a visual program

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is testing a program?
A Reading the blocks once and hoping they are right
B Running it with chosen inputs and comparing what happens to what you expected
2. Which one is a test input for a quiz program that asks for a number between 1 and 10?
A Typing 5 into the ask box
B Changing the sprite's costume
3. When should you work out the expected result?
A Before you run the test
B After you see what the program does
4. A program says 'You pass!' if score > 50. You test with a score of 80 and expect 'You pass!'. It says 'You pass!'. What does this tell you?
A The whole program is now fully tested
B The result matched, so this path works
5. A program has an if-else block. How many paths do you need to test?
A Both the if path and the else path
B Only the if path

Match the Pairs

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

Left columnRight column
1Test input: age = 8 AExpected: 10, Actual: 10 -> Pass
2Expected: say "Too young" BWhat you predict the program should do before you run it
3Testing every path means trying an input for each branch of an if-else block CTest 1: age = 15 (if path) Test 2: age = 8 (else path)
4Testing means comparing the actual result with the expected result DOnly one path was tested. The else path was never checked, so a mistake there could be missed. Add a test input such as age = 8.
5Only test: age = 15 (if path only) ENo expected result was written first, so you cannot tell if the program is right or wrong. Decide what should happen before you run it.
6Run the program and see what happens (no expected result) FA chosen value you give the program to see how it behaves

Definitions

testing

Fill in the Blanks

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

1.
Test input: 20 ________ result: say Adult
2.
Test _____: 10 Expected result: say Child
3.
Test 1: age 20 checks the IF path Test 2: age 10 checks the ____ path
4.
ask [Enter your age] and wait if <______ > 17> then say [Adult]
5.
Expected: say Adult ______: say Child Result: FAIL

Spot the Error

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

Question 1
A Rule: if score > 10, say Win
B Test input: score = 15
C Expected: say Lose
D Actual: say Win
Question 2
A Rule: if age < 13, say Child
B Test input: age = 20
C Expected: say Child
Question 3
A Rule: if lives = 5, game over
B Test input: lives = 0
C Expected: say Game over
Question 4
A Rule: >10 says Win, else Try
B Test 1: score = 20, expect Win
C Test 2: score=30, expect Win
Question 5
A set score to 0
B repeat 5
C change score by 2
D Expected: score is 6

Answer Key

Testing a visual program
Section A: Quick Questions
Q1
B — Running it with chosen inputs and comparing what happens to what you expected
Q2
A — Typing 5 into the ask box
Q3
A — Before you run the test
Q4
B — The result matched, so this path works
Q5
A — Both the if path and the else path
Section B: Match the Pairs
Q1
Test input: age = 8 → A chosen value you give the program to see how it behaves
Q2
Expected: say "Too young" → What you predict the program should do before you run it
Q3
Testing every path means trying an input for each branch of an if-else block → Test 1: age = 15 (if path) Test 2: age = 8 (else path)
Q4
Testing means comparing the actual result with the expected result → Expected: 10, Actual: 10 -> Pass
Q5
Only test: age = 15 (if path only) → Only one path was tested. The else path was never checked, so a mistake there could be missed. Add a test input such as age = 8.
Q6
Run the program and see what happens (no expected result) → No expected result was written first, so you cannot tell if the program is right or wrong. Decide what should happen before you run it.
Section C: Definitions
Q1
testing — Running your program with chosen test inputs and comparing what happens to the result you expected. Test every path, so each branch of the program gets checked.
Section D: Fill in the Blanks
Q1
Test input: 20 Expected result: say Adult
Q2
Test input: 10 Expected result: say Child
Q3
Test 1: age 20 checks the IF path Test 2: age 10 checks the ELSE path
Q4
ask [Enter your age] and wait if <answer > 17> then say [Adult]
Q5
Expected: say Adult Actual: say Child Result: FAIL
Section E: Spot the Error
Q1
C — The rule says a score over 10 says Win. The test input is 15, so the expected result must be say Win, not say Lose.
Q2
B — The expected result is say Child, but age 20 is not under 13. The test input should be a number below 13, such as 8.
Q3
A — The test uses lives = 0 and expects Game over, so the rule must check for lives = 0. Checking for 5 would not match the test.
Q4
C — Both tests now use the Win path, so the else path is never checked. Test 2 should use a small score like 4 to test the Try path.
Q5
B — Repeating 5 times adds 2 each time, so the score would be 10, not the expected 6. The loop should be repeat 3.