Which is an edge case for a function that returns the average of a list?
Options
- A list with 3 normal numbers
- An empty list (division by zero) (Correct option)
- A list of positive integers
- A list sorted ascending
Answer
An empty list (division by zero)
Why
Edge cases are unusual or extreme inputs at the boundaries, where bugs like to hide: empty input, one element, zero, negative numbers, very large values, duplicates, None.
An average divides by the length; with an empty list that is division by zero. Decide what should happen (return None? raise ValueError?) and test it.
Remember
Always test empty, one, zero, negative, huge, None.