When writing (parameterized) tests for stateless functions, how do I determine the most ideal set of values to test with?
I'm writing a class with mathematical functions in C#, and I want to write unit tests for them. Today I want to write this function (really!):
int Clamp(int value, int lowerBound, int upperBound)
{
// TODO: Implement.
return 0;
}
As good TDD practice dictates, I'm writing the unit tests first and the implementation later. I can write a parameterized test for this stateless function, but have to decide on the best set of values to test with.
My current strategy for picking testing values is:
For each parameter, I can pick values from the whole set of 32-bit signed integers. I'm not using randomly generated values as that would make the test non-repeatable. To test the corner cases, I pick -1, 0, 1, but also the −2147483648 (minimum 32-bit signed integer) and 2147483647 (maximum 32-bit signed integer). I would also need to pick a 'normal' value, for example, 42, to make sure I'm not only testing corner cases. Is one normal value enough? And a negative one, let's say -63. Did I miss any?
−2147483648, -63, -1, 0, 1, 42, 2147483647
If any of the three parameters can have any of just these seven values, I'll end up with 343 tests for one function! Before I'm going to write 343 tests, I really have to ask:
Are these the right values to test with? In general, what strategy can I use to pick the most effective values to use?