When test cases come from the specification instead of the code, why does the suite survive a total rewrite of the function's internals?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Black box testing reads the docstring and nothing else. Here is the entire specification you are allowed to see:
def sqrt(x, epsilon): """assumes x, epsilon floats, x >= 0, epsilon > 0 returns res such that x-epsilon <= res*res <= x+epsilon"""
Someone has proposed six (x, epsilon) pairs as test cases in candidates. Some of them ask the function for something its author never promised. Keep only the pairs the specification allows, leaving them in the order they are listed, and assign that list to in_contract.
Test cases drawn from the specification alone
List a square-root suite taken only from the docstring — x of 0, a perfect square, a value below 1, irrationals and extremes, mixed with extreme epsilon values — and record its implementation independence.
Path-complete suites and boundary conditions
Write the cases a path-complete suite needs for if, elif and else and for loops entered zero, once and many times, then run the absolute-value function on 2, -2 and -1.
Named error types versus logic errors
List IndexError, TypeError, NameError and SyntaxError with a trigger for each, note IndentationError as a SyntaxError subclass, and record what marks a logic error instead.