| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 big = BigintOperations::NewFromInt64(kValue64); | 72 big = BigintOperations::NewFromInt64(kValue64); |
| 73 big_test = BigintOperations::Multiply(big_test, big_test); | 73 big_test = BigintOperations::Multiply(big_test, big_test); |
| 74 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); | 74 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); |
| 75 big = BigintOperations::NewFromInt64(-kValue64); | 75 big = BigintOperations::NewFromInt64(-kValue64); |
| 76 big_test = BigintOperations::Subtract( | 76 big_test = BigintOperations::Subtract( |
| 77 Bigint::Handle(BigintOperations::NewFromInt64(0)), big_test); | 77 Bigint::Handle(BigintOperations::NewFromInt64(0)), big_test); |
| 78 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); | 78 EXPECT_EQ(0, BigintOperations::Compare(big, big_test)); |
| 79 | 79 |
| 80 const Bigint& one = Bigint::Handle(BigintOperations::NewFromInt64(1)); | 80 const Bigint& one = Bigint::Handle(BigintOperations::NewFromInt64(1)); |
| 81 big = BigintOperations::NewFromInt64(kMinInt64); | 81 big = BigintOperations::NewFromInt64(kMinInt64); |
| 82 EXPECT(BigintOperations::FitsIntoMint(big)); | 82 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 83 int64_t back = BigintOperations::ToMint(big); | 83 int64_t back = BigintOperations::ToInt64(big); |
| 84 EXPECT_EQ(kMinInt64, back); | 84 EXPECT_EQ(kMinInt64, back); |
| 85 | 85 |
| 86 big = BigintOperations::Subtract(big, one); | 86 big = BigintOperations::Subtract(big, one); |
| 87 EXPECT(!BigintOperations::FitsIntoMint(big)); | 87 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 88 | 88 |
| 89 big = BigintOperations::NewFromInt64(kMaxInt64); | 89 big = BigintOperations::NewFromInt64(kMaxInt64); |
| 90 EXPECT(BigintOperations::FitsIntoMint(big)); | 90 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 91 back = BigintOperations::ToMint(big); | 91 back = BigintOperations::ToInt64(big); |
| 92 EXPECT_EQ(kMaxInt64, back); | 92 EXPECT_EQ(kMaxInt64, back); |
| 93 | 93 |
| 94 big = BigintOperations::Add(big, one); | 94 big = BigintOperations::Add(big, one); |
| 95 EXPECT(!BigintOperations::FitsIntoMint(big)); | 95 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 TEST_CASE(BigintUint64) { | 99 TEST_CASE(BigintUint64) { |
| 100 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUint64(1)); | 100 const Bigint& one = Bigint::Handle(BigintOperations::NewFromUint64(1)); |
| 101 EXPECT(BigintOperations::FitsIntoMint(one)); | 101 EXPECT(BigintOperations::FitsIntoInt64(one)); |
| 102 EXPECT(BigintOperations::FitsIntoUint64(one)); | 102 EXPECT(BigintOperations::FitsIntoUint64(one)); |
| 103 | 103 |
| 104 Bigint& big = Bigint::Handle(BigintOperations::NewFromUint64(kMaxUint64)); | 104 Bigint& big = Bigint::Handle(BigintOperations::NewFromUint64(kMaxUint64)); |
| 105 EXPECT(!BigintOperations::FitsIntoMint(big)); | 105 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 106 EXPECT(BigintOperations::FitsIntoUint64(big)); | 106 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 107 | 107 |
| 108 uint64_t back = BigintOperations::ToUint64(big); | 108 uint64_t back = BigintOperations::ToUint64(big); |
| 109 EXPECT_EQ(kMaxUint64, back); | 109 EXPECT_EQ(kMaxUint64, back); |
| 110 | 110 |
| 111 big = BigintOperations::Add(big, one); | 111 big = BigintOperations::Add(big, one); |
| 112 EXPECT(!BigintOperations::FitsIntoMint(big)); | 112 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 113 EXPECT(!BigintOperations::FitsIntoUint64(big)); | 113 EXPECT(!BigintOperations::FitsIntoUint64(big)); |
| 114 | 114 |
| 115 big = BigintOperations::Subtract(big, one); | 115 big = BigintOperations::Subtract(big, one); |
| 116 EXPECT(!BigintOperations::FitsIntoMint(big)); | 116 EXPECT(!BigintOperations::FitsIntoInt64(big)); |
| 117 EXPECT(BigintOperations::FitsIntoUint64(big)); | 117 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 118 | 118 |
| 119 big = BigintOperations::ShiftRight(big, 1); | 119 big = BigintOperations::ShiftRight(big, 1); |
| 120 EXPECT(BigintOperations::FitsIntoMint(big)); | 120 EXPECT(BigintOperations::FitsIntoInt64(big)); |
| 121 EXPECT(BigintOperations::FitsIntoUint64(big)); | 121 EXPECT(BigintOperations::FitsIntoUint64(big)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 TEST_CASE(BigintDouble) { | 125 TEST_CASE(BigintDouble) { |
| 126 Smi& smi = Smi::Handle(Smi::New(5)); | 126 Smi& smi = Smi::Handle(Smi::New(5)); |
| 127 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); | 127 Bigint& bigint = Bigint::Handle(BigintOperations::NewFromSmi(smi)); |
| 128 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); | 128 Double& dbl = Double::Handle(BigintOperations::ToDouble(bigint)); |
| 129 EXPECT_EQ(5.0, dbl.value()); | 129 EXPECT_EQ(5.0, dbl.value()); |
| 130 | 130 |
| (...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 "123456789012345678901234567890123456789012345678901234567890123456789012" | 2225 "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 2226 "345678901234567890123456789012345678901234567890123456789012345678901234" | 2226 "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 2227 "567890123456789012345678901234567890123456789012345678901234567890123456" | 2227 "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 2228 "789012345678901234567890123456789012345678901234567890123456789012345678" | 2228 "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 2229 "90123456789012345678901234567890", | 2229 "90123456789012345678901234567890", |
| 2230 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" | 2230 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" |
| 2231 "01234567890ABCDEE"); | 2231 "01234567890ABCDEE"); |
| 2232 } | 2232 } |
| 2233 | 2233 |
| 2234 } // namespace dart | 2234 } // namespace dart |
| OLD | NEW |