Skip to content
Tactiverge

School/◇ Explorer/Week 27

Design challenge 3: test it and make it better

Your design works on your first try. Is it finished?

About 30 min · 3 goals · Checked by automated tests; not yet reviewed by an educator

1.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.

2.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?

Guess first. Being wrong here is how the surprise works.

3.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.

If / else rule tester

A robot has a distance sensor on its nose. Write its rule, then move the reading and watch which branch runs. Try readings exactly on the threshold.

IF distance < 20 cm THEN Stop ELSE Drive forward

Comparison
20 cm
35 cm

Is 35 < 20? No, so the ELSE branch runs: Drive forward.

Every reading from 0 to 100 cm (lime = THEN, cobalt = ELSE):

050100 cm
Test cases (good testers always try the edges)
ReadingConditionAction
5 cmtrueStop
19 cmtrueStop
20 cmfalseDrive forward
21 cmfalseDrive forward
60 cmfalseDrive forward
100 cmfalseDrive forward
Can't use the interactive? Read a description instead

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.

4.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

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.

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.

5.Practice

Practice, not a test. Wrong answers get a hint and another try.

Practice 1 · a fresh version every time

Rule: IF temperature > 40 °C THEN switch the fan on. The sensor reads 41 °C, 55 °C, 40 °C, 33 °C, 43 °C, 47 °C. For how many of these readings does the THEN branch run?

Practice 2

Why write the expected result before running a test?

Practice 3

You change your rule from < to ≤ to fix one failed test. What should you do next?

Practice 4

Good practice tests each threshold at just below, exactly on, and just above it. A design has 3 thresholds. How many boundary tests is that?

6.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.

Open BUILD 003: Create an Intelligent Sorting Machine →

7.Reflect

Concepts: Testing and debugging · The design cycle and prototyping