1

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?

Doc Brown
  • 199,015
  • 33
  • 367
  • 565
cpx
  • 369
  • 1
  • 3
  • 13
  • 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. – Ben Cottrell May 07 '21 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 07 '21 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](https://people.bath.ac.uk/rjg20/training/intro-testing/07-edges/) and *"Edge cases deal with the extreme maximums and minimums of parameters."* [Source](https://www.uxbeginner.com/glossary/edge-case/). – cpx May 07 '21 at 14:09
  • @BenCottrell: Any good resource or reference you might know of? – cpx May 07 '21 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 08 '21 at 21:35
  • Don't think of it quantitatively in general; imagine instead a range of circumstances, an area of applicability where some solution works well (or some model/description captures the problem in a satisfactory way) - think of it as of an area on a map, a region on the landscape of possibilities. Once you get to the "edge" of that region, you run into circumstances that don't fit well with the given solution or model. Thus, those are "edge cases". (Edges may be fuzzy.) If this space of possibilities can be expressed in terms of parameters, then you can also describe these ranges quantitatively. – Filip Milovanović May 10 '21 at 14:49
  • Now, it might be hard to see how this kind of thinking might be applied to something like strings, but as an informal illustration, suppose you associate all possible values a string variable can take to points in a multidimensional mathematical space; then you can say that an algorithm works one way for a certain volume in that space (standard case), employs special-case logic for the edges (boundaries) of that volume (and perhaps for some "satellite" volumes of interest), and possibly does not work at all for any of the cases that fall outside of those boundaries. – Filip Milovanović May 10 '21 at 15:03

1 Answers1

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.
Christophe
  • 74,672
  • 10
  • 115
  • 187
  • 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 07 '21 at 16:46
  • 1
    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 07 '21 at 19:10