Every programming problem needs decomposing so that it can be properly understood. From this, an algorithm can be designed and tested.
wet_calc ← 1.5
OUTPUT “What speed is the go-kart travelling at?”
speed ← USERINPUT
WHILE (speed IS NOT integer) OR (speed < 10) OR(speed > 50) DO
OUTPUT “Speed must be a whole number between 10 and 50. Try again.”
speed ← USERINPUT
ENDWHILE
OUTPUT “Is the ground wet? (yes/no)”
wet_ground ← USERINPUT
IF wet_gound = “yes” THEN
braking_dist ← (speed * 5)* wet_calc
ELSE
braking_dist ← speed * 5
ENDIF
OUTPUT “The braking distance is: “ + braking_dist + “m”
Tests will be required to test that the final program runs correctly.
Test no | Description | Test data | Test type | Expected outcome |
---|---|---|---|---|
1 | Calculate normal speed on dry ground | 20, no | Normal | 100m |
2 | Calculate normal speed on wet ground | 20, yes | Normal | 150m |
3 | Borderline calculate normal speed on dry ground | 10, no | Boundary | 50m |
4 | Borderline calculate normal speed on wet ground | 10, no | Boundary | 75m |
5 | Test rejected input - below minimum | 5, yes | Erroneous | Asked to input again |
6 | Test rejected input - above maximum | 100, yes | Erroneous | Asked to input again |
7 | Test rejected input - not a number | ten, yes | Erroneous | Asked to input again |
The problem has now been fully decomposed and an algorithm has been designed.