GoalTrace flowcharts that choose and call sub-routines, pick comparison operators and test the boundary of a condition.
New words
selection · a choice in an algorithm: the answer to a yes/no question decides which steps are followedcomparison operator · a symbol such as <, <=, >, >=, == or != that compares two valuesboundary value · test data exactly on the edge of a condition, such as 30 for bill >= 30sub-routine · a named mini-program that the main program can run again and again
Explanation
A flowchart uses a diamond for selection. The condition inside the diamond is true or false, and only one branch is followed on each run. Sequence means that steps follow each other in a row. The operators < and > leave out the number itself, but <= and >= include it, so a small change of operator changes the answer at the boundary. That is why a good test plan has a test on the boundary and one on each side of it. A sub-routine is drawn in a main flowchart as a box that runs it, and the real symbol is a box with double lines at the sides. When the sub-routine has finished, the main flowchart carries on with the next step. A flowchart with sub-routines is shorter and easier to test, because each part can be checked on its own.
Operator
Means
Is the number itself included?
<
less than
no
<=
less than or equal to
yes
>
greater than
no
>=
greater than or equal to
yes
==
equal to
only that number
!=
not equal to
every number except that one
Worked examples
A fruit stall gives free delivery when the bill is 30 or more. The flowchart has a sequence of three steps and then one selection. Trace price = 6 and kg = 5: the bill is 30, the condition bill >= 30 is true, so it outputs Free delivery.
Test
Test data
Expected outcome
Actual outcome
Pass/fail
1
price = 4, kg = 7 (bill 28)
Delivery costs 4
Delivery costs 4
pass
2
price = 6, kg = 5 (bill 30)
Free delivery
Delivery costs 4
fail
3
price = 9, kg = 4 (bill 36)
Free delivery
Free delivery
pass
4
price = 3, kg = 0 (bill 0)
Delivery costs 4
Delivery costs 4
pass
This test plan was used on a faulty copy of the stall flowchart whose diamond says bill > 30. The expected outcomes were worked out by hand from the rules of the stall. Test 2 sits on the boundary and fails, so only a boundary test finds this bug.
A flowchart can choose which sub-routine to run. The sub-routine close_windows outputs Close the windows and Bring the washing in. The sub-routine open_windows outputs Open the windows. For rain = 12 the condition is true and two lines are shown. For rain = 10 or rain = 0 it is false and one line is shown.
Class activity
Boundary bingo (no computer): write the rule ‘a child can ride if the height is at least 110 cm’ on a card. Each player writes five heights between 100 and 120 cm on a grid. A partner reads out a height, and you say Ride or Too small before marking it. Then change the rule to ‘taller than 110 cm’. Which heights change their answer? Write down what you notice about the boundary.
Practice
1
Trace the flowchart for 5 lessons and for 6 lessons. What is output each time? What is the largest number of lessons that stays within the budget?
5 lessons: cost = 35, and 35 > 40 is false, so it outputs Within budget. 6 lessons: cost = 42, and 42 > 40 is true, so it outputs Over budget. The largest number of lessons within the budget is 5.
2
The rule is: children aged 5 or under get free entry. One test fails. Which test, what kind of error is it, and what must be changed in the flowchart?
Test
Test data
Expected outcome
Actual outcome
Pass/fail
1
age = 3
Free entry
Free entry
pass
2
age = 5
Free entry
Pay at the desk
?
3
age = 8
Pay at the desk
Pay at the desk
pass
Test 2 fails. The program runs and gives a wrong answer, so it is a logic error. The condition must include 5, so the diamond should say age <= 5 and not age < 5.
3
Follow the flowchart for 4 guests and for 8 guests. The sub-routine set_table outputs Plates out and Cups out. Write every line that is output each time.
For 4 guests: Plates out, Cups out, Ready (3 lines). For 8 guests the sub-routine runs twice: Plates out, Cups out, Plates out, Cups out, Ready (5 lines). Writing set_table once and running it twice saves drawing the same steps again.
4
Draw a flowchart on paper: the user types a height in centimetres. If it is 120 or more, it outputs You may ride; otherwise it outputs Too small. Then choose three test heights, including the boundary, and write the expected outcomes.
Start, then a parallelogram INPUT height, then a diamond height >= 120? The yes branch goes to OUTPUT "You may ride" and the no branch goes to OUTPUT "Too small"; both end at Stop. Tests: 119 gives Too small, 120 gives You may ride (the boundary), 135 gives You may ride.