AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Choices and loops on the board

Week 19 · Unit 8: Be an innovator · 3 lessons
3

Test with a range of data

Computing 6: Unit 8, pp. 106–123
GoalChoose normal and boundary test data, write expected results and use them to find bugs in a program.
New words
test data · the values that we give to a program to check that it worksexpected result · the answer that a correct program should giveboundary value · a value at the edge of a rule, such as 120 when the rule is 120 or moretest table · a table that lists the test data, the expected result and the actual result
Explanation

A program that works with one number may fail with another. To test a program properly we use a range of data. Normal data is a typical value that is well inside the rule. Boundary data is a value on the edge of the rule and the values just next to it. Many bugs hide at the edges, for example when we write > instead of ≥. Before we run a test, we write the expected result in a test table, using the rule and not the program. Then we run the program and write the actual result. If they are different, there is a bug. We find it, fix it and run all the tests again.

Kind of testRule: 120 or moreExpected
normal150yes
normal80no
boundary119no
boundary120yes
boundary121yes
Worked examples
setheightto120show iconyesshow iconnoifheight≥120thenelseon buttonApressed
The rule says that a child can ride if they are 120 cm tall or taller. This program follows the rule with the test value 120. The condition 120 ≥ 120 is true, so it shows yes.
heightExpectedActual (with >)Result
150yesyespass
80nonopass
120yesnoFAIL
121yesyespass
A programmer wrote > instead of ≥. Two normal tests pass, so the bug is not noticed. Only the boundary test at 120 shows it: the child should be allowed but the program says no.
itemsExpectedWhy this test
2no discountnormal, well below the rule
4no discountjust below the edge
5discounton the edge
6discountjust above the edge
A shop gives a discount for 5 or more items. The boundary values are 4, 5 and 6. A good test plan checks the edge, and both of its sides.
Class activity

Find the secret rule (no computer): Player A secretly chooses one of two rules, ‘more than 12’ or ‘12 or more’, and writes it down. Player B may give the machine only three numbers, and A says yes or no for each. Which three numbers should B choose to find out the rule? Play again with different rules, for example ‘under 30’ and ‘30 or under’. Write a test table for each game. What did you notice about the number on the edge? If you have a computer or tablet, build the ride program in a micro:bit simulator and run your test table.

Practice
1
A program shows pass if mark ≥ 50, and fail if not. Write three boundary tests with the expected results.
2
The rule is that a club is for ages 12 and over. Trace the program with age 12. Is it right? If not, fix it.
setageto12show iconyesshow iconnoifage>12thenelseon buttonApressed
3
A program should show yes when score ≥ 10. A pupil tested it with the three values below and all were correct. Is this enough? What would you add?
scoreExpectedActual
3nono
25yesyes
80yesyes
4
List test data for the rule ‘children under 5 get free entry’. Include normal and boundary values.