Lite / Discovering How the World Works / Week 27
Design challenge 3: test it and make it better
Your design works on your first try. Is it finished?
Why should I care?
Engineers test because confidence without evidence is just hope. A good test plan finds problems on paper or in simulation, where they're cheap, rather than in a real classroom, greenhouse or Mars crater, where they're not. Then the design cycle goes round again.
- Write test cases with expected results, including edge cases.
- Run tests and record pass or fail honestly.
- Make one evidence-based improvement and re-test.
Predict
Your rule is 'IF distance < 20 cm THEN stop'. You test it at 50 cm and 5 cm and both pass. Which extra test is most likely to find a problem?
- 40 cm
- Exactly 20 cm
- 60 cm
Guess first, then reveal
Exactly 20 cm. At the threshold, '<' means the robot does NOT stop, which may not be what you intended. Tests far from the edge almost always pass; bugs live at the edges.
Discover
Set up the rule for your own design (or the stop rule). Look at the test-case table: 5, 19, 20, 21, 60 and 100 cm. Does every row do what you'd want? If not, change the rule and check again.
What the interactive shows (text version)
The rule tester can be replaced by this test table for IF distance < 20 cm THEN stop ELSE drive: 5 cm → stop (pass); 19 cm → stop (pass); 20 cm → drive (a designer who wanted the robot to stop at 20 cm would record this as a fail and change < to ≤); 21 cm → drive; 60 cm → drive; 100 cm → drive.
Understand
Test cases
A test case is an input plus the result you expect, written down before you run it. Then you run it and record the actual result. Pass if they match, fail if they don't. Writing the expectation first stops you fooling yourself.
Pick tests that bite
Cover normal cases, edge cases (exactly on a threshold, zero, the maximum) and odd cases (a glitchy reading, two sensors at once). A test that can't fail teaches you nothing.
Improve, then re-test
When a test fails, find out why, change one thing, and run all the tests again. Then record what changed and what the evidence showed. That loop of design, test, improve is the design cycle, and it's how every real product gets good.
Explain it another way
Intuitive
Before a bridge opens, engineers drive heavy lorries over it. They don't test with a bicycle: they test with something that might actually break it.
Technical
Boundary-value testing checks inputs at, just below and just above every threshold, because off-by-one mistakes (using < instead of ≤) cluster there. Regression testing re-runs all earlier tests after every change.
Applied
Car makers test emergency braking with dummies stepping out at exactly the worst moment, in rain, at night. Each failed test leads to a change, then the whole test suite runs again.
Worked example 1
Write four test cases for a fan rule 'IF temperature > 26 °C THEN fan on ELSE fan off'.
| Input | Expected | Why | |---|---|---| | 20 °C | off | normal cool | | 26 °C | off | edge: not greater | | 27 °C | on | just above edge | | 35 °C | on | normal hot |
If you actually wanted the fan on at 26 °C, the edge test reveals it, and you'd change > to ≥.
Common mix-ups
If it works once, it's finished.
✓ One success proves very little. Test the edges and the odd cases too.A failed test means the design is bad.
✓ A failed test is useful evidence. Finding it now is much cheaper than finding it later.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Finish your term project: write at least five test cases (including one exactly on a threshold), run them by hand or in a Tactiverge simulator, and record expected vs actual. Make one improvement, re-run every test, and write two sentences on what changed and what the evidence showed.
Reflect
What did testing teach you about your design that you didn't know when you designed it?
Write your answer on paper or in your own notes. Lite never stores what you write.