This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove flawed tests from t/op/rand.t
authorDavid Mitchell <davem@iabyn.com>
Mon, 30 Nov 2015 13:51:30 +0000 (13:51 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 30 Nov 2015 13:51:30 +0000 (13:51 +0000)
commitf0bf11b219764f72d70d85e011ac6cd69cdea182
tree2fa226b5efc151180b40b96fa5bbcc70352215ef
parent4c298843f44226ef4a0089b71a623720a7aea3e6
remove flawed tests from t/op/rand.t

There is a section of code supposedly intended to check that
d_randbits bits is sane. AFIKT, the code was flawed from the start,
and has just become more broken since.

Initially it ran rand(1) many times and recorded the min and max.
It then (in a convoluted way involving logarithms) checked that
$max wasn't greater than 1.

I suspect that this code was (at least at one point during its initial
writing) supposed to check that the number of bit of precision in rand()
matched d_randbits. If that was the case, then it certainly wasn't doing
that.

Subsequently, extra bogus tests were added, e.g. that
    $max < (2 ** $randbits)
which it always will be, since it should be < 1.

Then the main test was inadvertently broken by a precedence issue
involving '!': I don't think this does what you think it does:

    unless (ok( !$max <= 0 or $max >= (2 ** $randbits)))

Then an extra check was added after each call to rand(1) in the loop that
the result was in the range 0..1. This check made all the other checks
that follow on $min and and $max superfluous.

So this commit removes all those extra tests, and changes a couple
of 'print #...\n"' into diag("..."), since we're now in the 21st century
:-)
t/op/rand.t