This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix bitwise op test; clean up a couple of others
[perl5.git] / t / lib / bigintpm.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 use Config;
9 use Math::BigInt;
10
11 $test = 0;
12 $| = 1;
13 print "1..246\n";
14 while (<DATA>) {
15        chop;
16        if (s/^&//) {
17                $f = $_;
18        } else {
19                ++$test;
20                @args = split(/:/,$_,99);
21                $ans = pop(@args);
22                $try = "\$x = new Math::BigInt \"$args[0]\";";
23                if ($f eq "bnorm"){
24                    $try .= "\$x+0;";
25                } elsif ($f eq "bneg") {
26                    $try .= "-\$x;";
27                } elsif ($f eq "babs") {
28                    $try .= "abs \$x;";
29                } else {
30                    $try .= "\$y = new Math::BigInt \"$args[1]\";";
31                    if ($f eq bcmp){
32                        $try .= "\$x <=> \$y;";
33                    }elsif ($f eq badd){
34                        $try .= "\$x + \$y;";
35                    }elsif ($f eq bsub){
36                        $try .= "\$x - \$y;";
37                    }elsif ($f eq bmul){
38                        $try .= "\$x * \$y;";
39                    }elsif ($f eq bdiv){
40                        $try .= "\$x / \$y;";
41                    }elsif ($f eq bmod){
42                        $try .= "\$x % \$y;";
43                    }elsif ($f eq bgcd){
44                        $try .= "Math::BigInt::bgcd(\$x, \$y);";
45                    } else { warn "Unknown op"; }
46                }
47                #print ">>>",$try,"<<<\n";
48                $ans1 = eval $try;
49                if ("$ans1" eq $ans) { #bug!
50                        print "ok $test\n";
51                } else {
52                        print "not ok $test\n";
53                        print "# '$try' expected: '$ans' got: '$ans1'\n";
54                }
55        }
56
57 __END__
58 &bnorm
59 abc:NaN
60    1 a:NaN
61 1bcd2:NaN
62 11111b:NaN
63 +1z:NaN
64 -1z:NaN
65 0:+0
66 +0:+0
67 +00:+0
68 +0 0 0:+0
69 000000  0000000   00000:+0
70 -0:+0
71 -0000:+0
72 +1:+1
73 +01:+1
74 +001:+1
75 +00000100000:+100000
76 123456789:+123456789
77 -1:-1
78 -01:-1
79 -001:-1
80 -123456789:-123456789
81 -00000100000:-100000
82 &bneg
83 abd:NaN
84 +0:+0
85 +1:-1
86 -1:+1
87 +123456789:-123456789
88 -123456789:+123456789
89 &babs
90 abc:NaN
91 +0:+0
92 +1:+1
93 -1:+1
94 +123456789:+123456789
95 -123456789:+123456789
96 &bcmp
97 abc:abc:NaN
98 abc:+0:NaN
99 +0:abc:NaN
100 +0:+0:+0
101 -1:+0:-1
102 +0:-1:+1
103 +1:+0:+1
104 +0:+1:-1
105 -1:+1:-1
106 +1:-1:+1
107 -1:-1:+0
108 +1:+1:+0
109 +123:+123:+0
110 +123:+12:+1
111 +12:+123:-1
112 -123:-123:+0
113 -123:-12:-1
114 -12:-123:+1
115 +123:+124:-1
116 +124:+123:+1
117 -123:-124:+1
118 -124:-123:-1
119 &badd
120 abc:abc:NaN
121 abc:+0:NaN
122 +0:abc:NaN
123 +0:+0:+0
124 +1:+0:+1
125 +0:+1:+1
126 +1:+1:+2
127 -1:+0:-1
128 +0:-1:-1
129 -1:-1:-2
130 -1:+1:+0
131 +1:-1:+0
132 +9:+1:+10
133 +99:+1:+100
134 +999:+1:+1000
135 +9999:+1:+10000
136 +99999:+1:+100000
137 +999999:+1:+1000000
138 +9999999:+1:+10000000
139 +99999999:+1:+100000000
140 +999999999:+1:+1000000000
141 +9999999999:+1:+10000000000
142 +99999999999:+1:+100000000000
143 +10:-1:+9
144 +100:-1:+99
145 +1000:-1:+999
146 +10000:-1:+9999
147 +100000:-1:+99999
148 +1000000:-1:+999999
149 +10000000:-1:+9999999
150 +100000000:-1:+99999999
151 +1000000000:-1:+999999999
152 +10000000000:-1:+9999999999
153 +123456789:+987654321:+1111111110
154 -123456789:+987654321:+864197532
155 -123456789:-987654321:-1111111110
156 +123456789:-987654321:-864197532
157 &bsub
158 abc:abc:NaN
159 abc:+0:NaN
160 +0:abc:NaN
161 +0:+0:+0
162 +1:+0:+1
163 +0:+1:-1
164 +1:+1:+0
165 -1:+0:-1
166 +0:-1:+1
167 -1:-1:+0
168 -1:+1:-2
169 +1:-1:+2
170 +9:+1:+8
171 +99:+1:+98
172 +999:+1:+998
173 +9999:+1:+9998
174 +99999:+1:+99998
175 +999999:+1:+999998
176 +9999999:+1:+9999998
177 +99999999:+1:+99999998
178 +999999999:+1:+999999998
179 +9999999999:+1:+9999999998
180 +99999999999:+1:+99999999998
181 +10:-1:+11
182 +100:-1:+101
183 +1000:-1:+1001
184 +10000:-1:+10001
185 +100000:-1:+100001
186 +1000000:-1:+1000001
187 +10000000:-1:+10000001
188 +100000000:-1:+100000001
189 +1000000000:-1:+1000000001
190 +10000000000:-1:+10000000001
191 +123456789:+987654321:-864197532
192 -123456789:+987654321:-1111111110
193 -123456789:-987654321:+864197532
194 +123456789:-987654321:+1111111110
195 &bmul
196 abc:abc:NaN
197 abc:+0:NaN
198 +0:abc:NaN
199 +0:+0:+0
200 +0:+1:+0
201 +1:+0:+0
202 +0:-1:+0
203 -1:+0:+0
204 +123456789123456789:+0:+0
205 +0:+123456789123456789:+0
206 -1:-1:+1
207 -1:+1:-1
208 +1:-1:-1
209 +1:+1:+1
210 +2:+3:+6
211 -2:+3:-6
212 +2:-3:-6
213 -2:-3:+6
214 +111:+111:+12321
215 +10101:+10101:+102030201
216 +1001001:+1001001:+1002003002001
217 +100010001:+100010001:+10002000300020001
218 +10000100001:+10000100001:+100002000030000200001
219 +11111111111:+9:+99999999999
220 +22222222222:+9:+199999999998
221 +33333333333:+9:+299999999997
222 +44444444444:+9:+399999999996
223 +55555555555:+9:+499999999995
224 +66666666666:+9:+599999999994
225 +77777777777:+9:+699999999993
226 +88888888888:+9:+799999999992
227 +99999999999:+9:+899999999991
228 &bdiv
229 abc:abc:NaN
230 abc:+1:abc:NaN
231 +1:abc:NaN
232 +0:+0:NaN
233 +0:+1:+0
234 +1:+0:NaN
235 +0:-1:+0
236 -1:+0:NaN
237 +1:+1:+1
238 -1:-1:+1
239 +1:-1:-1
240 -1:+1:-1
241 +1:+2:+0
242 +2:+1:+2
243 +1000000000:+9:+111111111
244 +2000000000:+9:+222222222
245 +3000000000:+9:+333333333
246 +4000000000:+9:+444444444
247 +5000000000:+9:+555555555
248 +6000000000:+9:+666666666
249 +7000000000:+9:+777777777
250 +8000000000:+9:+888888888
251 +9000000000:+9:+1000000000
252 +35500000:+113:+314159
253 +71000000:+226:+314159
254 +106500000:+339:+314159
255 +1000000000:+3:+333333333
256 +10:+5:+2
257 +100:+4:+25
258 +1000:+8:+125
259 +10000:+16:+625
260 +999999999999:+9:+111111111111
261 +999999999999:+99:+10101010101
262 +999999999999:+999:+1001001001
263 +999999999999:+9999:+100010001
264 +999999999999999:+99999:+10000100001
265 &bmod
266 abc:abc:NaN
267 abc:+1:abc:NaN
268 +1:abc:NaN
269 +0:+0:NaN
270 +0:+1:+0
271 +1:+0:NaN
272 +0:-1:+0
273 -1:+0:NaN
274 +1:+1:+0
275 -1:-1:+0
276 +1:-1:+0
277 -1:+1:+0
278 +1:+2:+1
279 +2:+1:+0
280 +1000000000:+9:+1
281 +2000000000:+9:+2
282 +3000000000:+9:+3
283 +4000000000:+9:+4
284 +5000000000:+9:+5
285 +6000000000:+9:+6
286 +7000000000:+9:+7
287 +8000000000:+9:+8
288 +9000000000:+9:+0
289 +35500000:+113:+33
290 +71000000:+226:+66
291 +106500000:+339:+99
292 +1000000000:+3:+1
293 +10:+5:+0
294 +100:+4:+0
295 +1000:+8:+0
296 +10000:+16:+0
297 +999999999999:+9:+0
298 +999999999999:+99:+0
299 +999999999999:+999:+0
300 +999999999999:+9999:+0
301 +999999999999999:+99999:+0
302 &bgcd
303 abc:abc:NaN
304 abc:+0:NaN
305 +0:abc:NaN
306 +0:+0:+0
307 +0:+1:+1
308 +1:+0:+1
309 +1:+1:+1
310 +2:+3:+1
311 +3:+2:+1
312 +100:+625:+25
313 +4096:+81:+1