A test case defines a function call, its input, and the behavior or result that should follow. Writing the expected result before running the code makes the specification concrete and gives you a way to check whether the implementation works. section 6.2.1
Build useful test cases by covering:
- Common cases, such as ordinary inputs and a single-item list. section 6.2.1
- Edge cases, such as tied longest words, empty strings, boundary values, negative numbers, or data at the beginning and end of a list. section 6.2.1 section 6.2.2
- Cases derived from the function’s rules: test both what the function normally does and special behavior it promises, such as returning the first tied result. section 6.2.2
- A manageable range of parameter values rather than every possible list size or numeric combination. section 6.2.2
Testing a longest-word function
A test case such as longest_word(['a', 'bb', 'ccc']) → 'ccc' checks an ordinary input. Additional cases can check a tie, a one-word list, and a list of empty strings. If a test fails, revise the code or its specification, then rerun the earlier tests as well as the new one; fixing one case can break another. section 6.2.1 section 6.3.1
>>> longest_word(['a', 'bb', 'ccc']) 'ccc'
Shows the compact Python prompt form of a test case: an input call followed by its expected result. section 6.2.1




















































