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

Testing against criteria

Week 25 · Unit 10: Be a game developer · 3 lessons
3

Test, fix and improve

Computing 5: Unit 10, pp. 129–144
GoalTest a game against its criteria, fix a bug that a test finds and add a new criterion.
New words
test plan · a list of things to do and the result that should happen for each onefix · to change the code so that a bug is goneimprove · to make a program better by adding a new criterionretest · to run the tests again after a change
Explanation

A test plan has one test for each criterion. We do the test and write the result. When a test fails, we look at the code that belongs to that criterion and find the bug. Then we fix it. After any change, we retest all the criteria, because a fix can break something that worked before. When every test passes, the program meets its criteria. Then we can improve it by adding a new criterion, and we write the tests for it first. A program is never finished until every criterion has a yes.

CriterionTestResult
5 A missed apple starts again at the toplet an apple fall past the basket?
Worked examples
CriterionResultNotes
1 Basket movesyes
2 Apple fallsyes
3 Score goes up by 1yes
4 New apple after a catchyes
5 New apple after a missnoapple stuck at the bottom
6 ‘You win!’ at 5yes
We run ‘Catch the apple’ and test each criterion. The apple code has no block for a missed apple, so criterion 5 fails. A missed apple stays stuck at the bottom edge of the stage, so no new apple falls and the game cannot reach a score of 5.
Applechange y by-10changescoreby1go to x:pick random-200to200y:150iftouchingBasket?thengo to x:pick random-200to200y:150ify position<-170thenrepeat untilscore=5
The fix is a second if block inside the loop. When the apple’s y position is below −170, it goes back to the top at a random place. After the fix we retest all six criteria.
Applewhenclickedsetscoreto0setmissesto0go to x:0y:150change y by-10changescoreby1go to x:pick random-200to200y:150iftouchingBasket?thenchangemissesby1go to x:pick random-200to200y:150sayGame overfor2secondsstopallifmisses=3thenify position<-170thenrepeat untilscore=5sayYou win!for2secondsstopall
Now we improve the game. New criterion 7: ‘The game says Game over when 3 apples have been missed.’ We need a new variable, misses. It starts at 0 and goes up by 1 for every miss.
Class activity

Test lab (3 players, paper). Draw a stage on paper and cut out a basket and an apple. Player 1 moves the apple down one square for every tap on the table. Player 2 moves the basket one square left or right when asked. Player 3 is the tester and holds the six criteria. Play until the apple reaches the bottom row. The tester ticks yes or no. Then change the rules so that a missed apple goes back to the top row, and play again. Which criterion changed from no to yes?

Practice
1
Look at this boat game test. Which criteria fail? Where should you look in the code first?
CriterionResult
1 The boat moves right with the right arrowyes
2 The boat moves left with the left arrowyes
3 Each fish caught gives 1 pointno
4 The game says ‘Well done!’ at 10 pointsno
2
A tester fixed criterion 5 of a game and then ran all the tests again. Why was the retest worth doing? What does the table show?
CriterionBefore the fixAfter the fix
1yesyes
2yesyes
3yesno
4yesyes
5noyes
3
Write a test for the criterion ‘The player starts with 3 lives’.
4
A new criterion says: ‘The game lasts 60 seconds, then it says Time up and stops.’ Which Scratch blocks could you use, and how would you test it?