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, min_length.

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.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

You have attempted 1 of 3 activities on this page