OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / bitvector / t / 28__chunklist.t
1 #!perl -w
2
3 use strict;
4 no strict "vars";
5
6 use Bit::Vector;
7
8 # ======================================================================
9 #   $value = $vector->Chunk_Read($bits,$offset);
10 #   $vector->Chunk_Store($bits,$offset,$value);
11 #   @values = $vector->Chunk_List_Read($bits);
12 #   $vector->Chunk_List_Store($bits,@values);
13 # ======================================================================
14
15 $limit = 1000;
16
17 $longbits = Bit::Vector::Long_Bits();
18
19 print "1..", 3*$longbits, "\n";
20
21 $set = Bit::Vector->new($limit+1);
22 $tst = $set->Shadow();
23
24 $set->Fill();
25 $set->Bit_Off(0);
26 $set->Bit_Off(1);
27 for ( $j = 4; $j <= $limit; $j += 2 ) { $set->Bit_Off($j); }
28 for ( $i = 3; ($j = $i * $i) <= $limit; $i += 2 )
29 {
30     for ( ; $j <= $limit; $j += $i ) { $set->Bit_Off($j); }
31 }
32
33 $n = 1;
34
35 for ( $bits = 1; $bits <= $longbits; $bits++ )
36 {
37     undef @primes;
38     $tst->Empty();
39     @primes = $set->Chunk_List_Read($bits);
40     $tst->Chunk_List_Store($bits,@primes);
41     if ($set->equal($tst))
42     {print "ok $n\n";} else {print "not ok $n\n";}
43     $n++;
44     undef @chunks;
45     $tst->Empty();
46     $ok = 1;
47     for ( $i = 0, $offset = 0; $offset <= $limit; $i++, $offset += $bits )
48     {
49         $chunks[$i] = $set->Chunk_Read($bits,$offset);
50         if ($primes[$i] != $chunks[$i]) { $ok = 0; }
51     }
52     if ($ok)
53     {print "ok $n\n";} else {print "not ok $n\n";}
54     $n++;
55     for ( $i = 0; $i <= $#chunks; $i++ )
56     {
57         $tst->Chunk_Store($bits,$i*$bits,$chunks[$i]);
58     }
59     if ($set->equal($tst))
60     {print "ok $n\n";} else {print "not ok $n\n";}
61     $n++;
62 }
63
64 __END__
65