| 1 |
$| = 1; print "1..3000\n"; |
| 2 |
|
| 3 |
no warnings; |
| 4 |
use Array::Heap; |
| 5 |
|
| 6 |
srand 0; |
| 7 |
|
| 8 |
my @x = (1..10, map rand, 1..100); |
| 9 |
my $err; |
| 10 |
|
| 11 |
my @test = ( |
| 12 |
sub { push_heap_cmp { $a <=> $b } @x, rand }, |
| 13 |
sub { push_heap @x, rand }, |
| 14 |
sub { push_heap_cmp { $a <=> $b } @x, 1 + rand, 3 + rand}, |
| 15 |
sub { push_heap @x, 1 + rand, 3 + rand}, |
| 16 |
sub { pop_heap_cmp { $a <=> $b } @x }, |
| 17 |
sub { pop_heap @x }, |
| 18 |
sub { splice_heap_cmp { $a <=> $b } @x, int rand @x }, |
| 19 |
sub { splice_heap @x, int rand @x }, |
| 20 |
); |
| 21 |
|
| 22 |
sub chk { |
| 23 |
for (1 .. $#x) { |
| 24 |
if (!($x[$_] > $x[($_ - 1) >> 1])) { |
| 25 |
$err = "\$x[$_] ($x[$_]) !> \$x[$_ >> 1] ($x[($_ - 1) >> 1])"; |
| 26 |
make_heap @x; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
make_heap @x; |
| 32 |
chk; |
| 33 |
|
| 34 |
for (1..3000) { |
| 35 |
undef $err; |
| 36 |
my $t = int rand @test; |
| 37 |
$test[$t]->(); |
| 38 |
chk; |
| 39 |
print defined $err ? "not " : "", "ok $_ # $t,$err\n"; |
| 40 |
} |