S3U

Science / Programming basics / Grade 10 / sca70

Programming Basics: Test the Edges

Turn a requirement into test cases before editing a program.

All worksheets
5 questions0m 0s
Learn the skill

Requirement: accept whole-number levels from 1 through 5, inclusive. Valid types are integers only. Build tests for each endpoint, just outside each endpoint, an ordinary interior value and a wrong type. A passing sample is evidence, not a universal proof.

Worked example

For integer inputs 0, 1, 3, 5 and 6, expected outcomes are reject, accept, accept, accept and reject. The text "3" is rejected under this contract even though it contains a digit.

The contract accepts only integers from one through five. Integer zero is rejected, one and five are accepted, and six is rejected. The text string three is rejected because it is not an integer.
The contract accepts only integers from one through five. Integer zero is rejected, one and five are accepted, and six is rejected. The text string three is rejected because it is not an integer.
Question 1 Should integer 1 be accepted?
Question 2 Should integer 6 be accepted?
Question 3 Should the text "3" be accepted under this contract?
Question 4 A bug uses level < 5 instead of level <= 5. Which test exposes it?
Question 5 Do these few passing examples prove correctness for every possible input?