← Year 9 Space

Testing an algorithm: where does it fail?

Good tests include the boundary and the strange cases, not just easy ones. Test the triangle checker on a set of inputs and find where it gives the wrong answer.

The machine's first program says 3, 4 and 7 make a triangle. What would it cut?

A programmer changes the machine's check to "if S is greater than or equal to L, say triangle". It looks fine, so the machine goes into production. Have a guess which three strips would make it cut a frame that cannot close, and we'll come back to the machine at the end.

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Which strips break it

The check says triangle when S is greater than OR EQUAL to L. Which strips are most likely to fool it?

TryTry it on the board and compare the result with your prediction.

The boundary

The strips are 3, 4 and 7. What is S minus L?

InvestigateWork out why it happens, one step at a time.

Kinds of test case

Worked exampleBefore each step, say what you think comes next.
  1. 3, 4, 5: S=7>53,\ 4,\ 5:\ S = 7 > 5Typical, correct.
Build up to it
Is a test where S and L are equal on the edge of the rule or far from it?

Which kind of test is 3, 4 and 7?

Test 2.5, 2.5 and 5. What is S minus L?

Ravi tests the checker. Click the line that is the weak point of his testing.

ModifyChange the problem on purpose and see what happens.

Design tests

Which set of tests would find the fault in the S >= L check?

A strip has length 0. What should the checker say?

Strips 1, 1 and 2. What is S minus L?

PractiseA few on your own, to check you have it.

Run the tests

Test 4, 5 and 9. By how much does S exceed L?

The check S >= L says triangle for 4, 5 and 9. Is it right?

Review: strips 6, 9 and 14. What is S minus L?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Test the machine's check

Which kind of test found each fault? Typical, boundary or odd input?

Also used in

The check says triangle if S >= L. Run it on these five cases: (3, 4, 5), (3, 4, 7), (0, 4, 4), (1, 1, 1) and (2, 3, 9). How many does it get wrong? (The lengths are made up for the task.)

Work it out on paper first, one step per line. Then type your answer.

Now you can
Practise this skillNew questions, new numbers each timeGet 3 right in a row to mark it practised.Next lesson8. Refine it and explain the changeFix the failed tests with a smaller change, retest, and say what changed and why. Then extend the algorithm to say whether the triangle has a right, acute or obtuse angle.
For teachers

Good tests include the boundary and the strange cases, not just easy ones. Test the triangle checker on a set of inputs and find where it gives the wrong answer. About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Students need the last lesson.

The one idea: algorithms break at the edges, so tests must include boundary and odd cases. The S >= L fault is deliberate. Lengths are made up.

Running the lesson

  1. Predict: show of hands before the check.
  2. Make: the working is done on paper first.

The hard part (on purpose)

Testing only easy cases. Ask: what is the closest case to the edge of the rule?

When students get stuck

Stretch and support

Stretch: Design a test set of five cases that finds every fault in a checker.

Support: A printed copy of the situation and a blank table to fill in.

Where it leads

Continues AC9M9SP03 node 2.

Where it leads: refining the algorithm (next).

What each step is for