Repaso
Español
TestingCoreTST-30

Which is an edge case for a function that returns the average of a list?

Options

  1. A list with 3 normal numbers
  2. An empty list (division by zero) (Correct option)
  3. A list of positive integers
  4. 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.

Key terms

Practice this question in Repaso