MantaBase wrote:
Corners?
Is that the programming term?
Just wondering. We call them end cases or end members. I was just wondering what the official term was. End member is a physical science term.
I believe that what you're refering to as end cases and my corner cases are the same thing. It is just a difference in how you visualize the problem. In a nutshell, here is how corner cases were explained to me. Say we have a function that simply takes an int and returns an int that is 10 larger. Very simple.
Code:
public int add10(int i) { return i + 10; }
Now visualize the input it as a mathematical function with the input i being a value on the x axis and the output a value on the y axis. So what are the acceptable values of x (not in terms of what will return a correct value, but what will the compiler allow me/you to pass to the function)? Anything greater than or equal to Integer.MIN and less than or equal to Integer.MAX, right? And for y it will be anything greater than Integer.MIN + 10 up to Integer.MAX. So now we have a square representing all possible combinations of input and output. Now the idea is that most errors are not going to be in the middle of this square, but around the edges and in the corners. So a good sequence of test inputs would probably be to start with 0, 1, 10, 1000, 1 million, -1 million to make sure things are working. Basic blackbox testing. Next jump to the far edges and see what happens when you try Integer.MAX - 2 which returns an incorrect result. We can grey out a small vertical strip along the rightmost edge that causes overflow. A more thorough testing would include the value of a corner and corner + 1 in every direction... same thing with the edges. A more difficult problem with two inputs and a return value has x,y inputs and a z return value with many more corners and edges to check.
BTW, you almost always want to test 0 and 1 because of their interesting math properties - screwing up something like 2^0 makes you feel pretty dumb! If it were a higher math problem, you would probably want to check
e, pi, etc.
By end cases, do you mean when to terminate a loop? You can approach it similiarly. BTW, this is more formal than what I was suggesting previously. I like the extreme programming philosphy of writing unit tests
before coding because it makes you think a bit harder about the problem and solution before wasting any time writing a bad implementation.