The big ideaTry a program with several examples. Compare what it does with what you want.
How it works
Try a program with several examples, not just one. One good try is only one try.
Write down the answer you want first, so a mismatch is easy to spot.
Pick small numbers, big numbers and zero.
Compare what you want with what you get. When they do not match, that is how you spot a bug.
How to test.
Example 1: One try hid the bug
Maya feeds a two into her doubling machine, and out comes a four.
Two doubled is four, so it matches, and Maya cheers.
But the machine adds two. 2 + 2 = 4, and 2 x 2 = 4 as well, so one example hid the bug.
Example 2: Another try shows it
Jonah feeds in a five. Five doubled should be ten, but the machine gives seven.
What we want and what we get do not match.
That mismatch is how we spot a bug.
Example 3: Several examples
Ms. Park tries lots of numbers: five gave seven, three gave five, and ten gave twelve.
We wanted ten, six and twenty. None of them match.
Maya opens the program and finds add two, where she meant times two.
Example 4: The fix works
Maya changes the program to times two.
She tries a two, a five and a ten, and gets 4, 10 and 20.
Every answer matches what she wants.
Words to know
example
One number you try in the program.
compare
Look at what you want and what you get, side by side.
mismatch
When what you get is not what you want.
bug
A mix-up in the steps.
Watch out
One example can hide a bug. Try several.
Do not only try examples you know will work. A bug hides from easy examples.
Do not skip the comparing. Without it, you cannot tell if the answer is what you want.
Neat steps can still hide a bug. Try them with examples.
Try it
A doubling machine gets 6 and gives out 12. Does it match?
A doubling machine gets 8 and gives out 10. Does it match?
Why is trying only one example not enough?
An add-two machine gets a 3. What comes out, and what do we want from a doubling machine?
Which numbers are good to try?
Answers: 1. Yes · 2. No · 3. One example can hide a bug · 4. 5, and we want 6 · 5. Small numbers, big numbers and zero
Try at homeThink of a rule together, like add three or double it. One of you is the machine. The other says numbers, and the machine answers by the rule. Try a small number, a big number and a zero before you guess the rule. Then swap!
For grown-upsPlay the Mission: think of a secret number rule together, like add three or double it. One of you is the machine, and the other says numbers. Try a small number, a big number and a zero before guessing the rule, then swap.
Open these notes on screenScan the code, or go to tutorpip.com.