Saturday, October 26, 2013

I'm not a native English speaker. In my native language I'm aware of some terms used to refer to the condition checked to stop a recursion, and to the condition checked for extreme, unlikely or super-simple cases. In English, I've encountered the terms "edge case", "corner case", "boundary case" and "base case", but I can't quite figure out the differences and which is used to refer to what; I'd love to get some summary of the differences between them.
In particular, I would be very happy if someone could provide annotations for the lines in the following code sample:
    int transmogrify(int n) {
1.      assert(n <= 1000000);
2.      if (n < 0) return -1;
3.      if (n == 1000000) return PRE_CALC;
4.      if (n == 0) return n+1;            // For stopping the recursion
5.      if (n == 1251) return 3077;
        return transmogrify(n-1);
    }
think it's:
  1. Sanity check
  2. Input check
  3. Boundary case? Edge case? Corner case?
  4. Base case? Boundary case?
  5. Corner case? Edge case?
shareimprove this question
2 
I believe edge and boundary are generally the same. But they refer to testing, not to checking conditions in code. –  Richard Dec 16 '11 at 13:49 

2 Answers

up vote16down voteaccepted
I'm not a native English speaker either. But according to Wikipedia:
  • Edge case occurs at an extreme (maximum or minimum) operating parameter.
  • Corner case occurs outside of normal operating parameters, specifically when multiple environmental variables or conditions are simultaneously at extreme levels, even though each parameter is within the specified range for that parameter. (The "outside normal operating parameters" obviously means something like "outside typical combination of operating parameters", not strictly "outside allowed operating parameters". That is, you're still within the valid parameter space, but near its corner.)
  • Boundary case occurs when one of inputs is at or just beyond maximum or minimum limits.
  • Base case is where Recursion ends.
So, the nomenclature seems to be totally confused, even though corner case seems to mean something a bit different (a combination of values) than edge and boundary cases, which are definitely synonymes. It's probably safe to say that edge, corner, and boundary cases are the same thing in common speech. Someone could mean to say different thing by each of them, but there's hardly any common agreement.
Your 1) and 2) are what you wrote, 3) is a edge/boundary case, 4) is a base case, and 5) is a special case.
shareimprove this answer
Regardless of the differences between the words, what you'd use to describe a test depends on thesemantics (meaning) of the test, not the exact code - In the example provided it's not obvious what each of the tests mean. That aside, here's how I understand them:
  • Sanity check = Does this even make sense? For example, if your application only outputs integers,sqrt(-1) does not make sense, and log(-1) is undefined no matter how sophisticated the mathematics library.
  • Input check = Tests the user input, as opposed to some internal data structure or the output of a function. For example, in Bash [ $# -gt 0 ] checks that you got at least one input parameter, which could also be a sanity check for a command like find or mail.
  • Edge / Boundary check = The maximum or minimum input which is expected to produce correct output. For example, a function which just adds one to a number will have an operating range from to - 1, since input smaller than can't be provided by the user and output larger than won't be useful.
  • Corner case check = A more complex boundary check (a corner is a two-dimensional boundary), for example combining and in a calculation.
  • Special case check = Non-obvious, non-boundary special values, for example log(1 + the smallest floating point number).

No comments:

Post a Comment