📐 Edge Case

5th Grade 💻 Coding

An edge case is an extreme situation or a value sitting exactly on a boundary — like a score of exactly 90, an empty list or the number zero — where programs tend to fail.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

When you write a condition like “if the score is greater than 90, it’s Excellent,” what happens with a score of exactly 90? If you meant for 90 to count as Excellent too, you needed “greater than or equal to.” Mistakes like this are sometimes called “off-by-one errors,” and they’re among the most common bugs in the world.

Good programmers test edge cases on purpose: the smallest and largest values, zero, a negative number, empty text, a list with one item or no items at all, and what happens if the user types a word instead of a number. Checking the edges saves you from surprises.

For example

  • An average calculator works perfectly — until someone asks for the average of an empty list, and the program tries to divide by zero.
  • A website asks “How old are you?” and someone types -5. What should the program do?

📌 Remember: Test the edges: zero, empty, smallest, largest, exactly on the line.

Quick quiz

  1. What is an edge case?

  2. Which of these is an edge case for a list?

  3. If “Excellent” means “greater than 90,” what does a score of 90 get?

🔎 Ask Thinkapedia another question