GCSE Python · Lesson 8 of 9

Test plans, trace tables and debugging

OCR J277 2.3 / AQA 8525 testing

Design normal, boundary and invalid tests for a function.

← All GCSE Python lessons

Tests and trace tables

A test plan should include expected results alongside actual outcomes. Trace tables reveal how variables and decisions change through an algorithm. Use normal, extreme and invalid inputs to assess reliability.

Watch out: If the actual output differs from the expected value, record the discrepancy and retest after fixing the code.

1 · Learn and predict

Read this worked example. Predict its output, run it in Python 3, and explain how variables change.

def discount(price, member):
    if price < 0:
        raise ValueError('price cannot be negative')
    if member:
        return round(price * 0.9, 2)
    return round(price, 2)

print(discount(20, True))

2 · Build independently

Design normal, boundary and invalid tests for a function. Work from the starter code before comparing with the solution.

Download starter + solution ZIP ↓

For a stretch challenge: add meaningful test data, handle an edge case and explain one design decision.

Reveal reference solution
def discount(price, member):
    if price < 0:
        raise ValueError('price cannot be negative')
    if member:
        return round(price * 0.9, 2)
    return round(price, 2)

def run_tests():
    cases = [(20,True,18.0), (0,True,0.0), (20,False,20.0)]
    for price, member, expected in cases:
        actual = discount(price, member)
        assert actual == expected, (price, actual, expected)
    try:
        discount(-1, True)
    except ValueError:
        pass
    else:
        raise AssertionError('Negative price should fail')
    print('All tests passed')

if __name__ == '__main__':
    run_tests()

The reference is one possible approach. Test your own program before comparing.

3 · Debug and explain

Question: What makes a test a boundary test?

Show explanation

It checks values at or immediately around the edge of a permitted range.

4 · Check your understanding

Which is a boundary value for age 11–18?

5 · Reflect

Explain one test you used, one problem you solved and one improvement you would make.

This records completion only in this browser and does not certify mastery.

Want extra practice? Try interactive Python tracing and debugging questions →