📖 Test and fix an algorithm
The rule
- An algorithm is a list of steps, in the right order, that always works.
- A step can hide a decision. “Open wider than half of AB” beats “open to 2 cm”.
- Test an algorithm on new cases: a short line, a long line, a slanted line.
- If it fails, find the step that broke. When the arcs miss, the width step is the culprit.
- Fix one step, then run the whole list again on every test case.
- Arcs from A and B cross twice only if the width is more than half of AB.
- A missing or swapped step breaks a list too. The ruler step needs P and Q from earlier steps.
- Using the whole of AB as the width is always more than half.
Examples
Pip opens to 2 cm. AB is 7 cm. Do the arcs cross? → No, the arcs miss
- Half of 7 cm is 3.5 cm
- Pip's width, 2 cm, is less than 3.5 cm
- So the arcs miss
A width less than half of AB cannot reach across.
Fix Pip's step so it works for every AB. → Open the compass to AB
- The arcs must cross, so the width must be more than half of AB
- The whole of AB is always more than half
- New step: open to AB
The whole of AB is always more than half of AB.
Pip skips the step “mark P and Q”. What breaks? → The ruler has no points to join
- The ruler step joins P and Q
- Without the marks there are no points to tap
- So the ruler step cannot run
Each step needs what the steps before it made.
Which test cases should you try on a new step list? → Short, long and slanted lines
- A short line may hide a width problem
- A long line shows if the width is too small
- A slanted line shows the steps do not depend on direction
Different cases catch different problems.
Watch out
- “It worked once, so it always works.” No: test on new cases too.
- “Change many steps at once.” No: fix one step, then test again, so you know what helped.
- “Half of AB is wide enough.” No: exactly half only makes the arcs touch. Go wider.