Wednesday, November 14, 2007

There are only 6 numbers you need to know when testing ...

... and they are -1, 0, 1, some, n - 1 and n.

Generally, if you algorithm works with these 6 variations on the input (-1 being the error case) it'll work with anything you want to throw at it.

If you've tight on time, I'd recommend testing at least 0, n and 1 (in that order) as they are normally the problem children.

And there is always an argument about how your algorithm should handle error cases. Does it cope with them softly by returning false or throwing an error, or violently by asserting?

Both are correct.

At least one should be present.

But if you are writing code with unit tests, testing inputs [-1, 0, 1, some, n - 1 and n], those tests will show how your functionality is suppose to be used and the ambiguity is reduced.

No comments: