A program can run without an exception and still produce the wrong answer. A test compares observed behavior with an expectation chosen from the intended behavior. A unit test focuses on a small piece of code, commonly a function.
Suppose a delivery fee is 4 units per package. For three packages the expected fee is 12; for zero it is 0. These expectations follow from the rule, not from copying the program’s result.
def delivery_fee(packages):
return packages * 4
assert delivery_fee(3) == 12
assert delivery_fee(0) == 0
print("Both examples passed")
Both examples passed
== compares values; assert raises AssertionError when the comparison is false. If an assertion fails, later lines do not run. Assertions can be disabled when Python runs with optimization (python -O), so do not rely on them for required input validation or security. Dedicated test frameworks provide richer reporting.
Zero is a boundary case: an edge of the ordinary input range. Passing two tests gives evidence for those cases, not proof for every input. A specification should also say whether fractional or negative package counts are allowed.