Skip to content
SPM Tuition
Computer Science · Problem solving and algorithms

Testing normal, boundary and invalid inputs

Your program worked when you tried it once, but your teacher says it is not tested enough.

Testing means running a program on chosen inputs and comparing the actual result with the expected one. Three kinds of input do the work: normal, boundary and invalid.

This lesson is part of problem solving and algorithms. Once you understand the three types, the deeper lesson on choosing test data from one specification shows how to build a full plan.

What are the three types?

Type Meaning Example for marks from 0 to 100
Normal Typical valid value 65
Boundary On the edge of the range, plus the first value outside 0, 100, and −1 and 101
Invalid Wrong kind of data, expected to be rejected “abc” or 72.5

Normal data proves the program works in the usual case. Boundary data proves the edges are coded exactly. Invalid data proves the program protects itself.

Worked example: a grading program

The rule is: a mark of 40 or more is a Pass, otherwise a Fail. Marks are whole numbers from 0 to 100.

A student writes:

INPUT mark
IF mark > 40 THEN
  OUTPUT "Pass"
ELSE
  OUTPUT "Fail"
END IF

Test with a normal value, 65. Expected: Pass. Actual: Pass. The student stops here and believes the program is correct.

What does the boundary test show?

Now test 40, the lowest mark that should pass. Expected: Pass. Actual: 40 > 40 is false, so the program outputs Fail.

Input Expected Actual Result
65 Pass Pass Matches
40 Pass Fail Fault found
39 Fail Fail Matches

The repair is one character: change > to >=. The table also shows why 39 belongs in the plan, because it checks that the fix did not let failing marks through.

What mistake should you avoid?

The mistake is to decide that a program is tested because it worked once. A single normal value tests one path out of several, and it cannot test the edge at all.

A better habit is to write three rows before you run anything: one normal, the two boundaries with their neighbours, and one invalid. Then fill in the actual column only after running.

Check yourself

A school fridge alarm should sound when the temperature is above 8 °C. The sensor reports whole numbers from −10 to 30. Choose at least five tests and say what each should do.

Answer

Normal: 5, no alarm. Boundary on the rule: 8, no alarm (not above 8), and 9, alarm. Edges of the sensor range: −10 and 30, both valid, with 30 sounding the alarm. Invalid: 31 or “hot”, which the program should reject.

The pair 8 and 9 is the key test, because it separates > from >=.

What to study next

Practise all four skills in this section with the problem solving and algorithms practice set. Keep a record of the test cases you forget using the mistake log and paper-error review.

If you want a teacher to go through your own test plans, see online one-to-one Computer Science tuition.

Common questions

What are the three types of test data?

Normal data is typical and valid. Boundary data sits on the edge of the valid range, including the values just beyond it. Invalid data should be rejected, such as a letter where a number is required.

Why is boundary data so important?

Errors cluster at the edges. A wrong comparison operator, such as > instead of >=, affects only the boundary value. Normal data passes either way, so it never shows this mistake.

Is a value just outside the range boundary or invalid data?

It is usually grouped with boundary testing because it checks the same edge from the other side. Some questions call it invalid data. Read the wording and follow what the question asks.

Do I need expected results before testing?

Yes. Work out what the program should output from the rule, write it down, then run the test. Comparing actual and expected results is what makes it a test rather than a demonstration.

If your program passes your own test but fails the teacher's, a one-to-one Computer Science teacher can help you choose the inputs that would have caught it.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.