in reply to Re: Testing Random Code
in thread Testing Random Code
You need to treat it as a black box ...
Agreed. But ...
PIN length is almost an invariant because it almost doesn't depend on any input data
I couldn't disagree more.
As pin() has no inputs, your assertion is based upon knowledge of what you know is inside the box, which is wrong. For a black box that takes no inputs and produces variable outputs, then only way to test is compare a representative sample of outputs against the specifications for those outputs.
Assuming pin() is defined to produce a random 4-digit integer; or better pin() is defined to produce a random value of type PIN, which is (currently) defined as a 4-digit integer; then the tests need to be:
For large ranges, you would rely upon statistics to sample the distribution, but since this is such a small range, and the generation takes so little time, you might as well saturation test it.
If you rely upon knowledge of the implementation to not bother checking for length 4, then a modification by someone not understanding the significance of "%04d" that omitted the zero would not be detected.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Testing Random Code
by xdg (Monsignor) on Sep 19, 2006 at 15:12 UTC |