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

Build it in small steps

Week 14 · 1.9 Physical computing · 3 lessons
2

Build, test, repeat

Computing 9: Topic 1.9, pp. 155–167
GoalFollow the loop of iterative development, and use a failed test to correct a micro:bit program one version at a time.
New words
iterative development · making a program one part at a time: build, test, decide what to do next, and repeatversion · one stage of a program as it grows, such as version 1 and version 2boundary test · a test with the value exactly at the edge of a rule, such as the 10th jump when the rule says 10 or more
Explanation

In iterative development you do not write the whole program at once. You write the requirements and choose the first part. Then you build it and test it. After the test you decide what to do: change the part if the idea was wrong, correct it if it does not work, or add the next part. After every change you test again, and you go on round the loop until all the requirements are met. Each pass gives a new version of the program. Tests should include the value at the edge of a rule, because a wrong comparison such as > instead of >= shows up there.

Plan a partBuild itTest itChange, correct or add
Worked examples
Jump counter, version 2setjumpsto0on startchangejumpsby1show numberjumpson shakesetjumpsto0show numberjumpson buttonBpressed
Version 2 adds requirement 2. Button B sets jumps to 0 and shows it. The test is: shake three times, press B, shake once. The lights show 1, 2, 3, then 0, then 1. The test passes, so the next part can be added.
TestShakesExpected lightsActual lightsResult
1999pass
210happy face10FAIL
311happy facehappy facepass
Version 3, first try. The programmer wrote jumps > 10 for the happy face, but the requirement says 10 jumps or more. The test plan below covers the edge of the rule. Test 2 fails: at 10 jumps the lights show the number 10, and the happy face should have appeared. The failing row is highlighted.
Jump counter, version 3setjumpsto0on startchangejumpsby1show iconhappyshow numberjumpsifjumps>9thenelseon shakesetjumpsto0show numberjumpson buttonBpressed
Version 3, corrected. The test showed the fault, so the comparison changed to jumps > 9. Now the 9th shake shows 9, the 10th shows the happy face, and the 11th shows the happy face again, because jumps is 11. Pressing B shows 0, and the next shake shows 1. The loop would now go round again for the next requirement.
Class activity

Build in layers (no computer). Cut paper strips and write on each strip one micro:bit block from the jump counter, such as set jumps to 0 or change jumps by 1. Build version 1 from the strips. A partner is the micro:bit: they say what the lights show after the events you call out, such as ‘shake, shake’. Then add the strips for version 2 and call out a new list of events that includes B. (If you have a micro:bit, the block editor and an adult nearby, you can build version 1 and shake it.)

Practice
1
The user presses A four times. What do the lights show after each press?
Pointssetpointsto0on startchangepointsby3show iconyesshow numberpointsifpoints>8thenelseon buttonApressed
2
The user shakes four times and then presses B. What do the lights show after the last press, and does the program meet the requirement ‘B starts again from 0’? How would you repair it?
Faulty versionsetjumpsto0on startchangejumpsby1show numberjumpson shakesetjumpsto0on buttonBpressed
3
Put these steps of iterative development in order: test the finished program; build the first part; decide to change, correct or add; write the requirements; test the part; choose which part to make first.
4
A rule says that the happy face must appear at 6 jumps or more. Write the condition for the IF block. Then write three tests, with the number of shakes and the lights you expect.