ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Array-Heap/t/01_rand.t
Revision: 1.1
Committed: Sun Jul 26 04:50:02 2009 UTC (14 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
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 $t;
9 my @x = (1..10, map rand, 1..100);
10 my $err;
11
12 my @test = (
13 sub { push_heap_cmp { $a <=> $b } @x, rand },
14 sub { push_heap @x, rand },
15 sub { push_heap_cmp { $a <=> $b } @x, 1 + rand, 3 + rand},
16 sub { push_heap @x, 1 + rand, 3 + rand},
17 sub { pop_heap_cmp { $a <=> $b } @x },
18 sub { pop_heap @x },
19 sub { splice_heap_cmp { $a <=> $b } @x, int rand @x },
20 sub { splice_heap @x, int rand @x },
21 );
22
23 sub chk {
24 for (1 .. $#x) {
25 if (!($x[$_] > $x[($_ - 1) >> 1])) {
26 $err = "($t) \$x[$_] ($x[$_]) !> \$x[$_ >> 1] ($x[($_ - 1) >> 1])\n";
27 make_heap @x;
28 }
29 }
30 }
31
32 make_heap @x;
33 chk;
34
35 for (1..3000) {
36 undef $err;
37 $t = int rand @test;
38 $test[$t]->();
39 chk;
40 print defined $err ? "not " : "", "ok $_ # $err\n";
41 }