0

An edge case is usually defined as what Wikipedia would say,

An edge case is a problem or situation that occurs only at an extreme (maximum or minimum) operating parameter. For example, a stereo speaker might noticeably distort audio when played at maximum volume, even in the absence of any other extreme setting or condition.

Apart from wikipedia, here are some more definitions from the top search results which sound very similar and source of confusion: "The situation where the test examines either the beginning or the end of a range, but not the middle, is called an edge case." Source and "Edge cases deal with the extreme maximums and minimums of parameters." Source.

There is also this older SE question from 2011, where the top answers speak about edge cases occuring at extreme (maximum or minimum) operating parameters.

These definitions sound quantitative e.g. you need to test minimum or maximum values.

Also, there were examples given here: How do you identify “edge” cases on algorithms?:

String with some known special cases:

  • Unicode string (special characters)
  • If limited to a specific set of characters, what happens when some are not in the range
  • Odd/even length string
  • Non-null terminated

Sort algorithm that could fail in the following boundary cases:

  • Duplicate elements
  • Collection with all elements equal
  • Odd/even length input

How are these string and sort algorithm examples fall under boundary cases or, extreme cases, or, minimum or maximum value?

Aren't these simply "special cases" rather than saying there's an edge, boundary to them?

7
  • 7
    Wikipedia is not an authority on word or phrase definitions for the English language. In every-day speak, the term 'edge case' is frequently understood (by native speakers) to simply mean "Something which is not usual or expected". Indeed, the terms 'edge case' and 'special case' are commonly used interchangeably by native English speakers because only an extremely small minority of the population are particularly bothered about splitting hairs over slight differences in semantics. May 7, 2021 at 13:55
  • By definition, if you consider the domain of an algorithm to be N-dimensional where N is the number of bits in its input, every case is an "edge" case for a particular unit vector in N-space.
    – trent
    May 7, 2021 at 14:05
  • Apart from wikipedia, here are some more definitions from the top search results which sound very similar and source of confusion: "The situation where the test examines either the beginning or the end of a range, but not the middle, is called an edge case." Source and "Edge cases deal with the extreme maximums and minimums of parameters." Source.
    – cpx
    May 7, 2021 at 14:09
  • @BenCottrell: Any good resource or reference you might know of?
    – cpx
    May 7, 2021 at 14:40
  • @cpx: I edited this information into the question (BTW, you could have done this by yourself). Also, voted to reopen now.
    – Doc Brown
    May 8, 2021 at 21:35

1 Answer 1

4

The wording from wikipedia is not well chosen:

  • The terms "maximum" and "minimum" only make sense for operating parameters having values that are within a finite bound and on which there is a single order, such as for example scalars.
  • A parameter can be a object of a type where maximum/minimum value does not even have a meaning. Take a complex number for example: is (10, 2) greater than (2,10) ? Or what are the extreme parameter for a picture: a full white picture, a full black picture, a picture of only 1x1 pixels size or a huge image ?

The edge case is simply an extreme case but not necessarily related to extreme values. And an extreme case is indeed a special case, but some special cases are rather ordinary, without soliciting to the extreme any boundaries that you may have in your code.


A couple of examples with strings:

  • what happens if the string is empty ? One could say it's a minimum case, since the length of the string is the minimum (you cannot imagine the number of out-of-bounds exception that this simple extreme case generates in untested software!)
  • when search something in a string: what happens if the occurence is at the very first or the very last position of a string? One could say these are minimum or maximum cases, since it's about minimum or maximum possible position.
  • if it's a character what happens for a single ascci value? And what happens with 🪂 (U+1FA82) which is one of the largest available unicode character? It's also a kind of maximum case since it's the maximum length for an UTF-8 encoded chacaracter (4 bytes), and also a maximum length in UTF-16 (2 words) that will break any badly written code assuming that UTF-16 is a fixed length encoding.
  • non null-terminated is a typical C issue: string manipulation functions work with null terminated strings, but some functions also work on a maximum length even if there is no null terminator. Mixing both kind of functions can lead to catastrophee (the maximu length preventinga terminating null, which another function would then process as an infinite string. One could again argue, that despite no maximum value, it's an extreme case, since it challenges the maximum length.
  • I agree with you on the ambiguity of odd/even length. It's not an extreme case, just many special cases. However, if you try several variants of code to recognize a palindrome, you'll understand why some people consider these as an extreme case.
2
  • Thanks, I guess it makes sense. Since the question was about "email validation" and "algorithm". Any idea about edge cases examples in that context (not considering those which are easily recognized and related to minimum / maximum value)? I have included some examples about "sort algorithm" in question as well which seem more interesting i.e. simply "special cases" than "extreme". It also appears that the words "edge case" and "special cases" are interchangeable. A few mix of these examples would be great along with string examples which are already given.
    – cpx
    May 7, 2021 at 16:46
  • For email validation, "", "@", "@." and "a@b.", "a@.b", "a@" and "@b",and "a" are edge cases playing with minimum length of the address or some of its elementary components. Another edge case would be very long string, such as one in with every component of the email address would be several kilobytes long, and andother in which the address would be a long sequence of "@", as well as an adress with extremely numberous and long components, and finally an address with many dots followed by @ and again many dots. Then there are certainly a couple of other special cases ;-)
    – Christophe
    May 7, 2021 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.