OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Testing Bigints with and without intrinsics. | 5 // Testing Bigints with and without intrinsics. |
6 // VMOptions= | 6 // VMOptions= |
7 // VMOptions=--no_intrinsify | 7 // VMOptions=--no_intrinsify |
8 // VMOptions=--optimization_counter_threshold=10 | 8 // VMOptions=--optimization_counter_threshold=10 |
9 | 9 |
10 library big_integer_test; | 10 library big_integer_test; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 Expect.equals(40128068573873018143207285483, x.modPow(e, m)); | 224 Expect.equals(40128068573873018143207285483, x.modPow(e, m)); |
225 } | 225 } |
226 | 226 |
227 testBigintModInverse() { | 227 testBigintModInverse() { |
228 var x, m; | 228 var x, m; |
229 x = 1; | 229 x = 1; |
230 m = 1; | 230 m = 1; |
231 Expect.equals(0, x.modInverse(m)); | 231 Expect.equals(0, x.modInverse(m)); |
232 x = 0; | 232 x = 0; |
233 m = 1000000001; | 233 m = 1000000001; |
234 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 234 Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime. |
235 x = 1234567890; | 235 x = 1234567890; |
236 m = 19; | 236 m = 19; |
237 Expect.equals(11, x.modInverse(m)); | 237 Expect.equals(11, x.modInverse(m)); |
238 x = 1234567890; | 238 x = 1234567890; |
239 m = 1000000001; | 239 m = 1000000001; |
240 Expect.equals(189108911, x.modInverse(m)); | 240 Expect.equals(189108911, x.modInverse(m)); |
241 x = 19; | 241 x = 19; |
242 m = 1000000001; | 242 m = 1000000001; |
243 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 243 Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime. |
244 x = 19; | 244 x = 19; |
245 m = 1234567890; | 245 m = 1234567890; |
246 Expect.equals(519818059, x.modInverse(m)); | 246 Expect.equals(519818059, x.modInverse(m)); |
247 x = 1000000001; | 247 x = 1000000001; |
248 m = 1234567890; | 248 m = 1234567890; |
249 Expect.equals(1001100101, x.modInverse(m)); | 249 Expect.equals(1001100101, x.modInverse(m)); |
250 x = 1000000001; | 250 x = 1000000001; |
251 m = 19; | 251 m = 19; |
252 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 252 Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime. |
253 x = 12345678901234567890; | 253 x = 12345678901234567890; |
254 m = 19; | 254 m = 19; |
255 Expect.equals(3, x.modInverse(m)); | 255 Expect.equals(3, x.modInverse(m)); |
256 x = 12345678901234567890; | 256 x = 12345678901234567890; |
257 m = 10000000000000000001; | 257 m = 10000000000000000001; |
258 Expect.equals(9736746307686209582, x.modInverse(m)); | 258 Expect.equals(9736746307686209582, x.modInverse(m)); |
259 x = 19; | 259 x = 19; |
260 m = 10000000000000000001; | 260 m = 10000000000000000001; |
261 Expect.equals(6315789473684210527, x.modInverse(m)); | 261 Expect.equals(6315789473684210527, x.modInverse(m)); |
262 x = 19; | 262 x = 19; |
263 m = 12345678901234567890; | 263 m = 12345678901234567890; |
264 Expect.equals(10396361179987004539, x.modInverse(m)); | 264 Expect.equals(10396361179987004539, x.modInverse(m)); |
265 x = 10000000000000000001; | 265 x = 10000000000000000001; |
266 m = 12345678901234567890; | 266 m = 12345678901234567890; |
267 Expect.equals(325004555487045911, x.modInverse(m)); | 267 Expect.equals(325004555487045911, x.modInverse(m)); |
268 x = 10000000000000000001; | 268 x = 10000000000000000001; |
269 m = 19; | 269 m = 19; |
270 Expect.equals(7, x.modInverse(m)); | 270 Expect.equals(7, x.modInverse(m)); |
271 x = 12345678901234567890; | 271 x = 12345678901234567890; |
272 m = 10000000000000000001; | 272 m = 10000000000000000001; |
273 Expect.equals(9736746307686209582, x.modInverse(m)); | 273 Expect.equals(9736746307686209582, x.modInverse(m)); |
274 x = 12345678901234567890; | 274 x = 12345678901234567890; |
275 m = 19; | 275 m = 19; |
276 Expect.equals(3, x.modInverse(m)); | 276 Expect.equals(3, x.modInverse(m)); |
277 x = 123456789012345678901234567890; | 277 x = 123456789012345678901234567890; |
278 m = 123456789012345678901234567899; | 278 m = 123456789012345678901234567899; |
279 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 279 Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime. |
280 x = 123456789012345678901234567890; | 280 x = 123456789012345678901234567890; |
281 m = 123456789012345678901234567891; | 281 m = 123456789012345678901234567891; |
282 Expect.equals(123456789012345678901234567890, x.modInverse(m)); | 282 Expect.equals(123456789012345678901234567890, x.modInverse(m)); |
283 x = 123456789012345678901234567899; | 283 x = 123456789012345678901234567899; |
284 m = 123456789012345678901234567891; | 284 m = 123456789012345678901234567891; |
285 Expect.equals(77160493132716049313271604932, x.modInverse(m)); | 285 Expect.equals(77160493132716049313271604932, x.modInverse(m)); |
286 x = 123456789012345678901234567899; | 286 x = 123456789012345678901234567899; |
287 m = 123456789012345678901234567890; | 287 m = 123456789012345678901234567890; |
288 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime. | 288 Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime. |
289 x = 123456789012345678901234567891; | 289 x = 123456789012345678901234567891; |
290 m = 123456789012345678901234567890; | 290 m = 123456789012345678901234567890; |
291 Expect.equals(1, x.modInverse(m)); | 291 Expect.equals(1, x.modInverse(m)); |
292 x = 123456789012345678901234567891; | 292 x = 123456789012345678901234567891; |
293 m = 123456789012345678901234567899; | 293 m = 123456789012345678901234567899; |
294 Expect.equals(46296295879629629587962962962, x.modInverse(m)); | 294 Expect.equals(46296295879629629587962962962, x.modInverse(m)); |
295 } | 295 } |
296 | 296 |
297 testBigintGcd() { | 297 testBigintGcd() { |
298 var x, m; | 298 var x, m; |
299 x = 1; | 299 x = 1; |
300 m = 1; | 300 m = 1; |
301 Expect.equals(1, x.gcd(m)); | 301 Expect.equals(1, x.gcd(m)); |
302 x = 693; | 302 x = 693; |
303 m = 609; | 303 m = 609; |
304 Expect.equals(21, x.gcd(m)); | 304 Expect.equals(21, x.gcd(m)); |
305 x = 693 << 40; | 305 x = 693 << 40; |
306 m = 609 << 40; | 306 m = 609 << 40; |
307 Expect.equals(21 << 40, x.gcd(m)); | 307 Expect.equals(21 << 40, x.gcd(m)); |
308 x = 609 << 40;; | 308 x = 609 << 40;; |
309 m = 693 << 40;; | 309 m = 693 << 40;; |
310 Expect.equals(21 <<40, x.gcd(m)); | 310 Expect.equals(21 <<40, x.gcd(m)); |
311 x = 0; | 311 x = 0; |
312 m = 1000000001; | 312 m = 1000000001; |
313 Expect.throws(() => x.gcd(m), (e) => e is RangeError); | 313 Expect.throws(() => x.gcd(m), (e) => e is ArgumentError); |
314 x = 1000000001; | 314 x = 1000000001; |
315 m = 0; | 315 m = 0; |
316 Expect.throws(() => x.gcd(m), (e) => e is RangeError); | 316 Expect.throws(() => x.gcd(m), (e) => e is ArgumentError); |
317 x = 1234567890; | 317 x = 1234567890; |
318 m = 19; | 318 m = 19; |
319 Expect.equals(1, x.gcd(m)); | 319 Expect.equals(1, x.gcd(m)); |
320 x = 1234567890; | 320 x = 1234567890; |
321 m = 1000000001; | 321 m = 1000000001; |
322 Expect.equals(1, x.gcd(m)); | 322 Expect.equals(1, x.gcd(m)); |
323 x = 19; | 323 x = 19; |
324 m = 1000000001; | 324 m = 1000000001; |
325 Expect.equals(19, x.gcd(m)); | 325 Expect.equals(19, x.gcd(m)); |
326 x = 19; | 326 x = 19; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 testBigintNegate(); /// negate: ok | 413 testBigintNegate(); /// negate: ok |
414 testShiftAmount(); /// shift: ok | 414 testShiftAmount(); /// shift: ok |
415 Expect.equals(12345678901234567890, (12345678901234567890).abs()); | 415 Expect.equals(12345678901234567890, (12345678901234567890).abs()); |
416 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); | 416 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); |
417 var a = 10000000000000000000; | 417 var a = 10000000000000000000; |
418 var b = 10000000000000000001; | 418 var b = 10000000000000000001; |
419 Expect.equals(false, a.hashCode == b.hashCode); | 419 Expect.equals(false, a.hashCode == b.hashCode); |
420 Expect.equals(true, a.hashCode == (b - 1).hashCode); | 420 Expect.equals(true, a.hashCode == (b - 1).hashCode); |
421 } | 421 } |
422 } | 422 } |
OLD | NEW |