← All lessons

Lesson 18

Assertions & Edge Cases

An assertion checks a condition and raises AssertionError when it is false. It is useful for small tests, not validation of untrusted input.

A good test covers normal inputs and boundaries. For a passing threshold of 60, test 59, 60, and 61.

A failing test shows a mismatch, not automatically where the bug is. Keep tests specific so the wrong behavior is easy to identify.

def passes(score):
    return score >= 60
assert passes(60) is True
assert passes(59) is False
print("Tests passed")

Check your understanding

What happens when an assertion is false?

CHALLENGE

Define passes(score) for scores at least 60. Assert 60 passes and 59 fails, then print Tests passed.

Practice →
Next: While Loops →