ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Array-Heap/t/01_rand.t
Revision: 1.2
Committed: Sun Jul 26 05:25:18 2009 UTC (17 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_2, rel-3_1, rel-3_0, rel-2_0, rel-3_22, rel-3_21, HEAD
Changes since 1.1: +3 -4 lines
Log Message:
2.0

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 = (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 }