6 use Bit::Vector::String;
8 my @l = (31,32,33,127,128,129,1023,1024,1025);
10 my($b,$i,$n,$r,$s,$t,$u,$v,$w,$x);
12 print "1..", @l * 81, "\n";
16 # -------------------------------------------------------
20 $v = Bit::Vector->new($b);
21 $w = Bit::Vector->new($b);
23 for ( $i = 0; $i < 3; $i++ )
25 if ($i == 0) { $v->Primes(); }
26 elsif ($i == 1) { $v->Fill(); }
30 for ( $x = 0; $x < $b; $x += 12 ) { $v->Bit_On($x); }
31 if ($v->to_Oct() =~ /^[01]+$/)
32 {print "ok $n\n";} else {print "not ok $n\n";}
34 if ($v->to_Hex() =~ /^[01]+$/)
35 {print "ok $n\n";} else {print "not ok $n\n";}
39 # =======================================================
41 $x = '$w->from_Oct( $s = $v->to_Oct() );';
45 $w->from_Oct( $s = $v->to_Oct() );
47 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
50 $x = '$t = $w->String_Import( $s = $v->String_Export( $r ) );';
52 $t = $w->String_Import( $s = $v->String_Export( $r = 'bin' ) );
54 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
57 $t = $w->String_Import( $s = $v->String_Export( $r = 'oct' ) );
59 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
62 $t = $w->String_Import( $s = $v->String_Export( $r = 'hex' ) );
64 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
67 $t = $w->String_Import( $s = $v->String_Export( $r = 'dec' ) );
69 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
72 $t = $w->String_Import( $s = $v->String_Export( $r = 'enum' ) );
74 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
77 $t = $w->String_Import( $s = $v->String_Export( $r = 'pack' ) );
79 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
82 # =======================================================
84 $x = '$t = $w->String_Import( $s = $v->to_Type() );';
87 $t = $w->String_Import( $s = $v->to_Bin() );
89 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
95 $t = $w->String_Import( $s = $v->to_Oct() );
97 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
101 $t = $w->String_Import( $s = $v->to_Hex() );
103 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
108 $t = $w->String_Import( $s = $v->to_Dec() );
110 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
114 $t = $w->String_Import( $s = $v->to_Enum() );
116 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
120 $t = $w->String_Import( $s = ':' . $v->Size(). ':' . $v->Block_Read() );
122 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
125 # =======================================================
127 $x = '$w = Bit::Vector->new_Oct( $b, $s = $v->to_Oct() );';
131 $w = Bit::Vector->new_Oct( $b, $s = $v->to_Oct() );
133 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
136 $x = '($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r ) );';
138 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'bin' ) );
140 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
143 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'oct' ) );
145 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
148 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'hex' ) );
150 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
153 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'dec' ) );
155 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
158 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'enum' ) );
160 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
163 ($w,$t) = Bit::Vector->new_String( $b, $s = $v->String_Export( $r = 'pack' ) );
165 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
168 # =======================================================
170 $x = '$w = Bit::Vector->new_Oct( undef, $s = $v->to_Oct() );';
174 $w = Bit::Vector->new_Oct( undef, $s = $v->to_Oct() );
175 $w->Resize($b) if ($w->Size() != $b);
177 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
180 $x = '($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r ) );';
182 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'bin' ) );
183 $w->Resize($b) if ($w->Size() != $b);
185 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
188 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'oct' ) );
189 $w->Resize($b) if ($w->Size() != $b);
191 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
194 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'hex' ) );
195 $w->Resize($b) if ($w->Size() != $b);
197 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
200 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'dec' ) );
201 if ($w->Size() != $b)
203 if ($v->msb and $w->Size() < $b) # needs sign extension when increasing size
206 $w = Bit::Vector->new($b);
209 else { $w->Resize($b); }
212 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
215 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'enum' ) );
216 $w->Resize($b) if ($w->Size() != $b);
218 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
221 ($w,$t) = Bit::Vector->new_String( undef, $s = $v->String_Export( $r = 'pack' ) );
222 $w->Resize($b) if ($w->Size() != $b);
224 {print "ok $n\n";} else {print "not ok $n\n";trace($b,$r,$s,$t,$v,$w,$x);}
227 # =======================================================
229 } # for ( $i = 0; $i < 3; $i++ )
233 # -------------------------------------------------------
237 return 'bin' if ($_[0] == 1);
238 return 'oct' if ($_[0] == 2);
239 return 'dec' if ($_[0] == 3);
240 return 'hex' if ($_[0] == 4);
241 return 'enum' if ($_[0] == 5);
242 return 'pack' if ($_[0] == 6);
248 my($b,$r,$s,$t,$v,$w,$x) = @_;
251 warn( "$r, $b bits\n" );
252 warn( type($t) . ": <$s>\n" );
253 warn( "v = <" . $v->to_Hex() . ">\n" );
254 warn( "w = <" . $w->to_Hex() . ">\n" );