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

Side by Side Diff: runtime/vm/bigint_operations_test.cc

Issue 8351050: Print Bigints in decimal format. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
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 #include "vm/assert.h" 5 #include "vm/assert.h"
6 #include "vm/bigint_operations.h" 6 #include "vm/bigint_operations.h"
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/object_store.h" 8 #include "vm/object_store.h"
9 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
10 10
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 const char* test = "-12345678901234567890"; 360 const char* test = "-12345678901234567890";
361 const char* out = "-0xAB54A98CEB1F0AD2"; 361 const char* out = "-0xAB54A98CEB1F0AD2";
362 const Bigint& bigint = Bigint::Handle( 362 const Bigint& bigint = Bigint::Handle(
363 BigintOperations::NewFromCString(test)); 363 BigintOperations::NewFromCString(test));
364 const char* str = BigintOperations::ToHexCString(bigint, &ZoneAllocator); 364 const char* str = BigintOperations::ToHexCString(bigint, &ZoneAllocator);
365 EXPECT_STREQ(out, str); 365 EXPECT_STREQ(out, str);
366 } 366 }
367 } 367 }
368 368
369 369
370 TEST_CASE(BigintDecStrings) {
371 {
372 const Bigint& bigint = Bigint::Handle(
373 BigintOperations::NewFromCString("0x123"));
374 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
375 EXPECT_STREQ("291", str);
376 }
377
378 {
379 const Bigint& bigint = Bigint::Handle(
380 BigintOperations::NewFromCString("0xaBcEf"));
381 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
382 EXPECT_STREQ("703727", str);
383 }
384
385 {
386 const char* in = "0x123456789";
387 const Bigint& bigint = Bigint::Handle(
388 BigintOperations::NewFromCString(in));
389 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
390 EXPECT_STREQ("4886718345", str);
391 }
392
393 {
394 const char* in = "0xFFFFFFF";
395 const Bigint& bigint = Bigint::Handle(
396 BigintOperations::NewFromCString(in));
397 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
398 EXPECT_STREQ("268435455", str);
399 }
400
401 {
402 const char* in = "0x10000000";
403 const Bigint& bigint = Bigint::Handle(
404 BigintOperations::NewFromCString(in));
405 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
406 EXPECT_STREQ("268435456", str);
407 }
408
409 {
410 const char* in = "0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0";
411 const Bigint& bigint = Bigint::Handle(BigintOperations::NewFromCString(in));
412 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
413 EXPECT_STREQ("7141946863373290020600059860922167424469804758405880798960",
414 str);
415 }
416
417 {
418 const Bigint& bigint = Bigint::Handle(
419 BigintOperations::NewFromCString("-0x123"));
420 EXPECT(BigintOperations::FitsIntoSmi(bigint));
421 const Smi& smi = Smi::Handle(BigintOperations::ToSmi(bigint));
422 EXPECT_EQ(-291, smi.Value());
423 }
424
425 {
426 const Bigint& bigint = Bigint::Handle(
427 BigintOperations::NewFromCString("-0x123"));
428 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
429 EXPECT_STREQ("-291", str);
430 }
431
432 {
433 const Bigint& bigint = Bigint::Handle(
434 BigintOperations::NewFromCString("-0xaBcEf"));
435 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
436 EXPECT_STREQ("-703727", str);
437 }
438
439 {
440 const char* in = "-0x123456789";
441 const Bigint& bigint = Bigint::Handle(BigintOperations::NewFromCString(in));
442 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
443 EXPECT_STREQ("-4886718345", str);
444 }
445
446 {
447 const char* in = "-0x123456789ABCDEF01234567890ABCDEF0123456789ABCDEF0";
448 const Bigint& bigint = Bigint::Handle(BigintOperations::NewFromCString(in));
449 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
450 EXPECT_STREQ("-7141946863373290020600059860922167424469804758405880798960",
451 str);
452 }
453
454 {
455 const Bigint& bigint = Bigint::Handle(
456 BigintOperations::NewFromCString("0x00000123"));
457 EXPECT(BigintOperations::FitsIntoSmi(bigint));
458 const Smi& smi = Smi::Handle(BigintOperations::ToSmi(bigint));
459 EXPECT_EQ(0x123, smi.Value());
460 }
461
462 {
463 const Bigint& bigint = Bigint::Handle(
464 BigintOperations::NewFromCString("0x000000123"));
465 const char* str = BigintOperations::ToDecCString(bigint, &ZoneAllocator);
466 EXPECT_STREQ("291", str);
467 }
468 }
469
470
370 static void TestBigintCompare(const char* a, const char* b, int compare) { 471 static void TestBigintCompare(const char* a, const char* b, int compare) {
371 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a)); 472 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a));
372 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b)); 473 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b));
373 int computed_compare = BigintOperations::Compare(bigint_a, bigint_b); 474 int computed_compare = BigintOperations::Compare(bigint_a, bigint_b);
374 int inverted_compare = BigintOperations::Compare(bigint_b, bigint_a); 475 int inverted_compare = BigintOperations::Compare(bigint_b, bigint_a);
375 if (compare == 0) { 476 if (compare == 0) {
376 EXPECT(computed_compare == 0); 477 EXPECT(computed_compare == 0);
377 EXPECT(inverted_compare == 0); 478 EXPECT(inverted_compare == 0);
378 } else if (compare < 0) { 479 } else if (compare < 0) {
379 ASSERT(computed_compare < 0); 480 ASSERT(computed_compare < 0);
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 "123456789012345678901234567890123456789012345678901234567890123456789012" 2101 "123456789012345678901234567890123456789012345678901234567890123456789012"
2001 "345678901234567890123456789012345678901234567890123456789012345678901234" 2102 "345678901234567890123456789012345678901234567890123456789012345678901234"
2002 "567890123456789012345678901234567890123456789012345678901234567890123456" 2103 "567890123456789012345678901234567890123456789012345678901234567890123456"
2003 "789012345678901234567890123456789012345678901234567890123456789012345678" 2104 "789012345678901234567890123456789012345678901234567890123456789012345678"
2004 "90123456789012345678901234567890", 2105 "90123456789012345678901234567890",
2005 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" 2106 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF"
2006 "01234567890ABCDEE"); 2107 "01234567890ABCDEE");
2007 } 2108 }
2008 2109
2009 } // namespace dart 2110 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698