I think there are three different aspects of this problem that you are testing.
First: is my algorithm correct? That is, given a properly functioning random number generator, will they create dates that are randomly distributed over a range?
Second: are boundary cases handled correctly? That is, when a random number generator creates the highest or lowest acceptable values, will something break?
Third: does my algorithm implementation work? That is, given the well-known list of pseudo-random inputs, is the expected list of pseudo-random dates created?
The first two things are not what I would embed in a module testing kit. This is what I will prove when developing the system. I will probably do this by writing a test harness that generated millions of dates and ran a square-squared test, as daniel.rikowski suggested. I would also make sure that this test harness did not finish until it handled both extreme cases (assuming my range of random numbers is small enough so that I can avoid this). And I am documenting this, so that anyone who comes and tries to improve the algorithm will know that this is a violation.
The last thing I would do for unit test for. I need to know that it did not fit into the code, which violates its implementation of this algorithm. The first sign that I will get when this happens is that the test fails. Then I will return to the code and find out that someone else thought that they were fixing something and broke it. If someone corrects the algorithm, it will also help them fix this test.
Robert Rossney Nov 23 '08 at 1:41 2008-11-23 01:41
source share