Unit content
Errors, testing and debugging
Programs can fail in different ways, and finding the cause requires distinguishing the kind of failure from the symptom it produces.
Syntax, runtime and logic errors
A syntax error means the program text does not follow the language grammar.
A runtime error occurs during execution, for example when dividing by zero or accessing a missing resource.
A logic error produces a valid execution but the wrong result because the implemented algorithm does not match the intended behavior.
Tests
A test supplies a controlled situation and checks an expected result. Small automated tests make behavior repeatable:
assert square(5) == 25
assert square(-3) == 9
A passing test shows that one specified case behaves as expected; it does not prove the whole program correct.
Edge cases
Bugs often appear at boundaries: empty collections, zero values, maximum sizes, invalid input or unusual combinations of conditions. Tests should deliberately cover these cases.
Debugging
Debugging is the process of locating and explaining a defect. Useful techniques include reproducing the failure reliably, reducing it to a smaller case, inspecting state, stepping through execution and adding targeted diagnostic output.
The goal is not merely to make the symptom disappear, but to identify the incorrect assumption or state transition that caused it.