18.7. Testing Optional Parameters¶
If a function takes an optional parameter, one of the edge cases to test for is when no parameter value is supplied during execution. That will test whether the default value is being set correctly when the parameter is omitted.
Consider the following function, which counts the number of “long enough” words in a list. What counts as long enough is determined by an optional parameter,
What return value tests could we write to check whether it is implemented correctly? First, we could construct a list of words that has words of many lengths, including a degenerate empty string that has length 0. One return value test would omit
min_length and check that we got the right count. Other return value tests would supply
min_length and would include the edge case where
min_length is 0 and one where it is very large.