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

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

Issue 9625027: Fix bit-or and bit-xor for two negative bigints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/bigint_operations.cc ('k') | tests/co19/co19-runtime.status » ('j') | 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) 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 "0x4000000000000000"); 1023 "0x4000000000000000");
1024 TestBigintBitAnd("0x123456789ABCDEF01234567890", 1024 TestBigintBitAnd("0x123456789ABCDEF01234567890",
1025 "0x4000000000000000", // Max Smi for 64 bits + 1. 1025 "0x4000000000000000", // Max Smi for 64 bits + 1.
1026 "0x0"); 1026 "0x0");
1027 } 1027 }
1028 1028
1029 1029
1030 static void TestBigintBitOr(const char* a, const char* b, const char* result) { 1030 static void TestBigintBitOr(const char* a, const char* b, const char* result) {
1031 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a)); 1031 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a));
1032 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b)); 1032 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b));
1033 const Bigint& anded = 1033 const Bigint& ored =
1034 Bigint::Handle(BigintOperations::BitOr(bigint_a, bigint_b)); 1034 Bigint::Handle(BigintOperations::BitOr(bigint_a, bigint_b));
1035 const char* str_anded = BigintOperations::ToHexCString(anded, &ZoneAllocator); 1035 const char* str_ored = BigintOperations::ToHexCString(ored, &ZoneAllocator);
1036 EXPECT_STREQ(result, str_anded); 1036 EXPECT_STREQ(result, str_ored);
1037 const Bigint& anded2 = 1037 const Bigint& ored2 =
1038 Bigint::Handle(BigintOperations::BitOr(bigint_b, bigint_a)); 1038 Bigint::Handle(BigintOperations::BitOr(bigint_b, bigint_a));
1039 const char* str_anded2 = BigintOperations::ToHexCString(anded2, 1039 const char* str_ored2 = BigintOperations::ToHexCString(ored2, &ZoneAllocator);
1040 &ZoneAllocator); 1040 EXPECT_STREQ(result, str_ored2);
1041 EXPECT_STREQ(result, str_anded2);
1042 } 1041 }
1043 1042
1044 1043
1045 TEST_CASE(BigintBitOr) { 1044 TEST_CASE(BigintBitOr) {
1046 const char* zero = "0x0"; 1045 const char* zero = "0x0";
1047 const char* one = "0x1"; 1046 const char* one = "0x1";
1048 const char* minus_one = "-0x1"; 1047 const char* minus_one = "-0x1";
1049 1048
1050 TestBigintBitOr(one, zero, one); 1049 TestBigintBitOr(one, zero, one);
1051 TestBigintBitOr(one, one, one); 1050 TestBigintBitOr(one, one, one);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 TestBigintBitOr("-0x100000000000000", 1096 TestBigintBitOr("-0x100000000000000",
1098 "-0x100000000000000", 1097 "-0x100000000000000",
1099 "-0x100000000000000"); 1098 "-0x100000000000000");
1100 TestBigintBitOr("-0x10000000000000000", 1099 TestBigintBitOr("-0x10000000000000000",
1101 "-0x10000000000000000", 1100 "-0x10000000000000000",
1102 "-0x10000000000000000"); 1101 "-0x10000000000000000");
1103 TestBigintBitOr("-0x10000000", "-0x10000001", "-0x1"); 1102 TestBigintBitOr("-0x10000000", "-0x10000001", "-0x1");
1104 TestBigintBitOr("-0x100000000", "-0x100000001", "-0x1"); 1103 TestBigintBitOr("-0x100000000", "-0x100000001", "-0x1");
1105 TestBigintBitOr("-0x100000000000000", "-0x100000000000001", "-0x1"); 1104 TestBigintBitOr("-0x100000000000000", "-0x100000000000001", "-0x1");
1106 TestBigintBitOr("-0x10000000000000000", "-0x10000000000000001", "-0x1"); 1105 TestBigintBitOr("-0x10000000000000000", "-0x10000000000000001", "-0x1");
1106 TestBigintBitOr("-0x10000000000000000", "-0x1", "-0x1");
1107 } 1107 }
1108 1108
1109 1109
1110 static void TestBigintBitXor(const char* a, const char* b, const char* result) { 1110 static void TestBigintBitXor(const char* a, const char* b, const char* result) {
1111 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a)); 1111 const Bigint& bigint_a = Bigint::Handle(BigintOperations::NewFromCString(a));
1112 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b)); 1112 const Bigint& bigint_b = Bigint::Handle(BigintOperations::NewFromCString(b));
1113 const Bigint& xored = 1113 const Bigint& xored =
1114 Bigint::Handle(BigintOperations::BitXor(bigint_a, bigint_b)); 1114 Bigint::Handle(BigintOperations::BitXor(bigint_a, bigint_b));
1115 const char* str_xored = BigintOperations::ToHexCString(xored, &ZoneAllocator); 1115 const char* str_xored = BigintOperations::ToHexCString(xored, &ZoneAllocator);
1116 EXPECT_STREQ(result, str_xored); 1116 EXPECT_STREQ(result, str_xored);
1117 const Bigint& xored2 = 1117 const Bigint& xored2 =
1118 Bigint::Handle(BigintOperations::BitXor(bigint_b, bigint_a)); 1118 Bigint::Handle(BigintOperations::BitXor(bigint_b, bigint_a));
1119 const char* str_xored2 = BigintOperations::ToHexCString(xored2, 1119 const char* str_xored2 = BigintOperations::ToHexCString(xored2,
1120 &ZoneAllocator); 1120 &ZoneAllocator);
1121 EXPECT_STREQ(result, str_xored2); 1121 EXPECT_STREQ(result, str_xored2);
1122 const Bigint& xored3 =
1123 Bigint::Handle(BigintOperations::BitXor(bigint_a, xored2));
1124 const char* str_xored3 = BigintOperations::ToHexCString(xored3,
1125 &ZoneAllocator);
1126 EXPECT_STREQ(b, str_xored3);
1127 const Bigint& xored4 =
1128 Bigint::Handle(BigintOperations::BitXor(xored2, bigint_a));
1129 const char* str_xored4 = BigintOperations::ToHexCString(xored4,
1130 &ZoneAllocator);
1131 EXPECT_STREQ(b, str_xored4);
1132 const Bigint& xored5 =
1133 Bigint::Handle(BigintOperations::BitXor(bigint_b, xored2));
1134 const char* str_xored5 = BigintOperations::ToHexCString(xored5,
1135 &ZoneAllocator);
1136 EXPECT_STREQ(a, str_xored5);
1137 const Bigint& xored6 =
1138 Bigint::Handle(BigintOperations::BitXor(xored2, bigint_b));
1139 const char* str_xored6 = BigintOperations::ToHexCString(xored6,
1140 &ZoneAllocator);
1141 EXPECT_STREQ(a, str_xored6);
1122 } 1142 }
1123 1143
1124 1144
1125 TEST_CASE(BigintBitXor) { 1145 TEST_CASE(BigintBitXor) {
1126 const char* zero = "0x0"; 1146 const char* zero = "0x0";
1127 const char* one = "0x1"; 1147 const char* one = "0x1";
1128 const char* minus_one = "-0x1"; 1148 const char* minus_one = "-0x1";
1129 1149
1130 TestBigintBitXor(one, zero, one); 1150 TestBigintBitXor(one, zero, one);
1131 TestBigintBitXor(one, one, zero); 1151 TestBigintBitXor(one, one, zero);
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 "123456789012345678901234567890123456789012345678901234567890123456789012" 2128 "123456789012345678901234567890123456789012345678901234567890123456789012"
2109 "345678901234567890123456789012345678901234567890123456789012345678901234" 2129 "345678901234567890123456789012345678901234567890123456789012345678901234"
2110 "567890123456789012345678901234567890123456789012345678901234567890123456" 2130 "567890123456789012345678901234567890123456789012345678901234567890123456"
2111 "789012345678901234567890123456789012345678901234567890123456789012345678" 2131 "789012345678901234567890123456789012345678901234567890123456789012345678"
2112 "90123456789012345678901234567890", 2132 "90123456789012345678901234567890",
2113 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" 2133 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF"
2114 "01234567890ABCDEE"); 2134 "01234567890ABCDEE");
2115 } 2135 }
2116 2136
2117 } // namespace dart 2137 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bigint_operations.cc ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698