1 |
root |
1.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 |
root |
1.2 |
$err = "\$x[$_] ($x[$_]) !> \$x[$_ >> 1] ($x[($_ - 1) >> 1])"; |
26 |
root |
1.1 |
make_heap @x; |
27 |
|
|
} |
28 |
|
|
} |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
make_heap @x; |
32 |
|
|
chk; |
33 |
|
|
|
34 |
|
|
for (1..3000) { |
35 |
|
|
undef $err; |
36 |
root |
1.2 |
my $t = int rand @test; |
37 |
root |
1.1 |
$test[$t]->(); |
38 |
|
|
chk; |
39 |
root |
1.2 |
print defined $err ? "not " : "", "ok $_ # $t,$err\n"; |
40 |
root |
1.1 |
} |