ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Array-Heap/t/02_idx.t
Revision: 1.1
Committed: Fri Apr 19 20:00:54 2013 UTC (11 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_2, rel-3_1, rel-3_0, rel-3_22, rel-3_21, HEAD
Log Message:
*** empty log message ***

File Contents

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