Skip to content
Kendrick's Website Kendrick's GitHub Kendrick's Youtube Kendrick's Travel blog

Edge Case and Corner Case

3 min read
Cover

When working, we sometimes use terms like corner case or edge case. They are actually similar concepts but have slight differences.

This post explains both terms in detail.

Corner and edge

Corner Case

Corner cases mainly refer to unusual situations that occur at the 'extreme' conditions of algorithms or problems, i.e., at the limits of input value ranges or conditions. For example, in a number array sorting algorithm, cases where the array size is 0 or 1 could be corner cases. Such situations don't occur often in normal scenarios, but must be considered to ensure algorithm accuracy and robustness.

Corner cases refer to problems that occur under extreme conditions of algorithms or systems.

  1. Corner Cases in Sorting Algorithms: In algorithms that sort arrays, cases where the input array is an empty array or contains only one element are corner cases. These cases don't occur frequently in typical array sorting scenarios, but the algorithm must be able to handle these situations properly.

  2. Corner Cases in Numerical Calculations: In algorithms that calculate numbers, cases where 0, negative numbers, or extremely large values are input can be corner cases. For example, when negative numbers are input to a function that calculates square roots, this is a corner case that needs special handling.

  3. Speaker Audio Distortion: When a speaker distorts audio only at maximum volume, maximum bass, and high humidity environments

  4. Computer Server Reliability Issues: When a computer server becomes unreliable only when there are maximum processors (64), memory (512GB), and simultaneously logged-in users (10,000)

Edge Case

Edge cases refer to situations that occur at the boundary conditions of a system. These refer to problems that occur at conditions corresponding to the boundaries of system design or specifications. For example, problems that occur when user input exceeds a specific length in web applications, or date processing issues like February 29th are edge cases. Edge cases play an important role in strengthening system stability by testing the boundaries of typical usage scenarios.

Edge cases refer to situations that occur at the boundary conditions of systems. These often occur at the boundaries of system specifications or expected usage ranges.

  1. Web Form Input Value Edge Cases: In web forms that limit the maximum number of characters users can input, situations where exactly that limit value or one more character than that is input are edge cases. For example, inputting exactly 255 characters in an email address input field is an example.

  2. Date Processing Edge Cases: In systems that process specific dates, special dates like leap years (e.g., February 29th) or time zone changes (daylight saving time) are considered edge cases. These dates may need to be processed differently from normal date processing.

  3. Currency Conversion Rounding Issues: In financial apps, cases where calculations for specific amounts go wrong due to rounding errors during currency conversion

  4. Emoji Processing Issues: When messaging apps crash when sending messages containing rarely used or complex emojis or symbols

  5. Time Zone Mismatches: When scheduling software displays events in the wrong time zone for users crossing the international date line, causing confusion and missed appointments

Conclusion

Through the examples explained above, you can see that edge cases and corner cases deal with different situations. Edge cases generally occur when a single variable reaches an extreme, while corner cases occur when multiple variables simultaneously reach extreme conditions.

Illustrated Images