Robust programs · GCSE · OCR J277 2.3.2, AQA 8525 3.2.11, Edexcel 1CP2 6.1.6 · about 15 min
Iterative and final testing; normal, boundary, invalid and erroneous data; test plans in code.
[1 mark]A speed must be from 0 to 100. Which is boundary test data?
[1 mark]A speed must be from 0 to 100. Which is erroneous test data?
[1 mark]What is iterative testing?
[1 mark]When should the expected result in a test plan be worked out?
[1 mark]What does this program print?
def valid(s):
return 0 < s < 100
print(valid(0), valid(50), valid(100))The test program below has a boundary bug. Fix valid_speed so every test prints pass, without changing the tests. Then add two more tests of your own: one normal, one erroneous. All tests must pass.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def valid_speed(text):
"""True if text is a whole number from 0 to 100."""
return text.isdigit() and 0 < int(text) < 100
tests = [("50", True), ("0", True), ("100", True), ("101", False), ("-5", False), ("fast", False)]
for number, (data, expected) in enumerate(tests, start=1):
actual = valid_speed(data)
result = "pass" if actual == expected else "FAIL"
print(f"test {number}: {data!r} expected {expected}, got {actual}: {result}")Plan your program here, then type it in and press Run.
valid_code(text) for six-character class codes, and a list of tests for it, before you write the function." 50", with a space, normal or erroneous data for valid_speed? Decide what it should do, add a test, and make it pass.