Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: tests/corelib/big_integer_arith_vm_test.dart

Issue 1188843004: Implement modInverse for an even modulus. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/core/int.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 library big_integer_test; 9 library big_integer_test;
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 x = 123456789012345678901234567891; 216 x = 123456789012345678901234567891;
217 e = 123456789012345678901234567899; 217 e = 123456789012345678901234567899;
218 m = 123456789012345678901234567890; 218 m = 123456789012345678901234567890;
219 Expect.equals(1, x.modPow(e, m)); 219 Expect.equals(1, x.modPow(e, m));
220 x = 123456789012345678901234567891; 220 x = 123456789012345678901234567891;
221 e = 123456789012345678901234567890; 221 e = 123456789012345678901234567890;
222 m = 123456789012345678901234567899; 222 m = 123456789012345678901234567899;
223 Expect.equals(40128068573873018143207285483, x.modPow(e, m)); 223 Expect.equals(40128068573873018143207285483, x.modPow(e, m));
224 } 224 }
225 225
226 // TODO(regis): Remove once even modulus is implemented.
227 UnimplementedEvenModulusModInverse(x, m) {
228 Expect.equals(true, m.isEven);
229 try {
230 x.modInverse(m);
231 Expect.fail("Did not throw UnimplementedError");
232 } on UnimplementedError catch (e) {
233 }
234 }
235
236 testBigintModInverse() { 226 testBigintModInverse() {
237 var x, m; 227 var x, m;
228 x = 1;
229 m = 1;
230 Expect.equals(0, x.modInverse(m));
238 x = 0; 231 x = 0;
239 m = 1000000001; 232 m = 1000000001;
240 Expect.equals(0, x.modInverse(m)); // Not coprime. 233 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime.
241 x = 1234567890; 234 x = 1234567890;
242 m = 19; 235 m = 19;
243 Expect.equals(11, x.modInverse(m)); 236 Expect.equals(11, x.modInverse(m));
244 x = 1234567890; 237 x = 1234567890;
245 m = 1000000001; 238 m = 1000000001;
246 Expect.equals(189108911, x.modInverse(m)); 239 Expect.equals(189108911, x.modInverse(m));
247 x = 19; 240 x = 19;
248 m = 1000000001; 241 m = 1000000001;
249 Expect.equals(0, x.modInverse(m)); // Not coprime. 242 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime.
250 x = 19; 243 x = 19;
251 m = 1234567890; 244 m = 1234567890;
252 Expect.equals(519818059, x.modInverse(m)); 245 Expect.equals(519818059, x.modInverse(m));
253 x = 1000000001; 246 x = 1000000001;
254 m = 1234567890; 247 m = 1234567890;
255 Expect.equals(1001100101, x.modInverse(m)); 248 Expect.equals(1001100101, x.modInverse(m));
256 x = 1000000001; 249 x = 1000000001;
257 m = 19; 250 m = 19;
258 Expect.equals(0, x.modInverse(m)); // Not coprime. 251 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime.
259 x = 12345678901234567890; 252 x = 12345678901234567890;
260 m = 19; 253 m = 19;
261 Expect.equals(3, x.modInverse(m)); 254 Expect.equals(3, x.modInverse(m));
262 x = 12345678901234567890; 255 x = 12345678901234567890;
263 m = 10000000000000000001; 256 m = 10000000000000000001;
264 Expect.equals(9736746307686209582, x.modInverse(m)); 257 Expect.equals(9736746307686209582, x.modInverse(m));
265 x = 19; 258 x = 19;
266 m = 10000000000000000001; 259 m = 10000000000000000001;
267 Expect.equals(6315789473684210527, x.modInverse(m)); 260 Expect.equals(6315789473684210527, x.modInverse(m));
268 x = 19; 261 x = 19;
269 m = 12345678901234567890; 262 m = 12345678901234567890;
270 UnimplementedEvenModulusModInverse(x, m); 263 Expect.equals(10396361179987004539, x.modInverse(m));
271 x = 10000000000000000001; 264 x = 10000000000000000001;
272 m = 12345678901234567890; 265 m = 12345678901234567890;
273 UnimplementedEvenModulusModInverse(x, m); 266 Expect.equals(325004555487045911, x.modInverse(m));
274 x = 10000000000000000001; 267 x = 10000000000000000001;
275 m = 19; 268 m = 19;
276 Expect.equals(7, x.modInverse(m)); 269 Expect.equals(7, x.modInverse(m));
277 x = 12345678901234567890; 270 x = 12345678901234567890;
278 m = 10000000000000000001; 271 m = 10000000000000000001;
279 Expect.equals(9736746307686209582, x.modInverse(m)); 272 Expect.equals(9736746307686209582, x.modInverse(m));
280 x = 12345678901234567890; 273 x = 12345678901234567890;
281 m = 19; 274 m = 19;
282 Expect.equals(3, x.modInverse(m)); 275 Expect.equals(3, x.modInverse(m));
283 x = 123456789012345678901234567890; 276 x = 123456789012345678901234567890;
284 m = 123456789012345678901234567899; 277 m = 123456789012345678901234567899;
285 Expect.equals(0, x.modInverse(m)); // Not coprime. 278 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime.
286 x = 123456789012345678901234567890; 279 x = 123456789012345678901234567890;
287 m = 123456789012345678901234567891; 280 m = 123456789012345678901234567891;
288 Expect.equals(123456789012345678901234567890, x.modInverse(m)); 281 Expect.equals(123456789012345678901234567890, x.modInverse(m));
289 x = 123456789012345678901234567899; 282 x = 123456789012345678901234567899;
290 m = 123456789012345678901234567891; 283 m = 123456789012345678901234567891;
291 Expect.equals(77160493132716049313271604932, x.modInverse(m)); 284 Expect.equals(77160493132716049313271604932, x.modInverse(m));
292 x = 123456789012345678901234567899; 285 x = 123456789012345678901234567899;
293 m = 123456789012345678901234567890; 286 m = 123456789012345678901234567890;
294 UnimplementedEvenModulusModInverse(x, m); 287 Expect.throws(() => x.modInverse(m), (e) => e is RangeError); // Not coprime.
295 x = 123456789012345678901234567891; 288 x = 123456789012345678901234567891;
296 m = 123456789012345678901234567890; 289 m = 123456789012345678901234567890;
297 UnimplementedEvenModulusModInverse(x, m); 290 Expect.equals(1, x.modInverse(m));
298 x = 123456789012345678901234567891; 291 x = 123456789012345678901234567891;
299 m = 123456789012345678901234567899; 292 m = 123456789012345678901234567899;
300 Expect.equals(46296295879629629587962962962, x.modInverse(m)); 293 Expect.equals(46296295879629629587962962962, x.modInverse(m));
301 } 294 }
302 295
303 testBigintNegate() { 296 testBigintNegate() {
304 var a = 0xF000000000000000F; 297 var a = 0xF000000000000000F;
305 var b = ~a; // negate. 298 var b = ~a; // negate.
306 Expect.equals(-0xF0000000000000010, b); 299 Expect.equals(-0xF0000000000000010, b);
307 Expect.equals(0, a & b); 300 Expect.equals(0, a & b);
(...skipping 26 matching lines...) Expand all
334 testBigintModInverse(); 327 testBigintModInverse();
335 testBigintNegate(); 328 testBigintNegate();
336 testShiftAmount(); 329 testShiftAmount();
337 Expect.equals(12345678901234567890, (12345678901234567890).abs()); 330 Expect.equals(12345678901234567890, (12345678901234567890).abs());
338 Expect.equals(12345678901234567890, (-12345678901234567890).abs()); 331 Expect.equals(12345678901234567890, (-12345678901234567890).abs());
339 var a = 10000000000000000000; 332 var a = 10000000000000000000;
340 var b = 10000000000000000001; 333 var b = 10000000000000000001;
341 Expect.equals(false, a.hashCode == b.hashCode); 334 Expect.equals(false, a.hashCode == b.hashCode);
342 Expect.equals(true, a.hashCode == (b - 1).hashCode); 335 Expect.equals(true, a.hashCode == (b - 1).hashCode);
343 } 336 }
OLDNEW
« no previous file with comments | « sdk/lib/core/int.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698