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

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

Issue 559203003: Fix wrong conversion from double to bigint in overriden operators of new bigint. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 | « tests/co19/co19-dart2js.status ('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 // Testing Bigints. 4 // Testing Bigints.
5 // TODO(srdjan): Make sure the numbers are Bigint and not Mint or Smi. 5 // TODO(srdjan): Make sure the numbers are Bigint and not Mint or Smi.
6 6
7 library big_integer_test; 7 library big_integer_test;
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 9
10 class BigIntegerTest { 10 class BigIntegerTest {
(...skipping 15 matching lines...) Expand all
26 static testBigintAdd() { 26 static testBigintAdd() {
27 // Bigint and Smi. 27 // Bigint and Smi.
28 var a = 12345678901234567890; 28 var a = 12345678901234567890;
29 var b = 2; 29 var b = 2;
30 Expect.equals(12345678901234567892, a + b); 30 Expect.equals(12345678901234567892, a + b);
31 Expect.equals(12345678901234567892, b + a); 31 Expect.equals(12345678901234567892, b + a);
32 // Bigint and Bigint. 32 // Bigint and Bigint.
33 a = 10000000000000000001; 33 a = 10000000000000000001;
34 Expect.equals(20000000000000000002, a + a); 34 Expect.equals(20000000000000000002, a + a);
35 // Bigint and double. 35 // Bigint and double.
36 a = 100000000000.0; 36 a = 100000000000000000000.0;
37 b = 100000000000; 37 b = 200000000000000000000;
38 Expect.equals(200000000000.0, a + b); 38 Expect.isTrue((a + b) is double);
39 Expect.equals(200000000000.0, b + a); 39 Expect.equals(300000000000000000000.0, a + b);
40 Expect.isTrue((b + a) is double);
41 Expect.equals(300000000000000000000.0, b + a);
40 } 42 }
41 43
42 static testBigintSub() { 44 static testBigintSub() {
43 // Bigint and Smi. 45 // Bigint and Smi.
44 var a = 12345678901234567890; 46 var a = 12345678901234567890;
45 var b = 2; 47 var b = 2;
46 Expect.equals(12345678901234567888, a - b); 48 Expect.equals(12345678901234567888, a - b);
47 Expect.equals(-12345678901234567888, b - a); 49 Expect.equals(-12345678901234567888, b - a);
48 // Bigint and Bigint. 50 // Bigint and Bigint.
49 a = 10000000000000000001; 51 a = 10000000000000000001;
50 Expect.equals(20000000000000000002, a + a); 52 Expect.equals(20000000000000000002, a + a);
51 // Bigint and double. 53 // Bigint and double.
52 a = 100000000000.0; 54 a = 100000000000000000000.0;
53 b = 100000000000; 55 b = 200000000000000000000;
54 Expect.equals(200000000000.0, a + b); 56 Expect.isTrue((a + b) is double);
55 Expect.equals(200000000000.0, b + a); 57 Expect.equals(-100000000000000000000.0, a - b);
58 Expect.isTrue((b + a) is double);
59 Expect.equals(100000000000000000000.0, b - a);
56 Expect.equals(-1, 0xF00000000 - 0xF00000001); 60 Expect.equals(-1, 0xF00000000 - 0xF00000001);
57 } 61 }
58 62
59 static testBigintMul() { 63 static testBigintMul() {
60 // Bigint and Smi. 64 // Bigint and Smi.
61 var a = 12345678901234567890; 65 var a = 12345678901234567890;
62 var b = 10; 66 var b = 10;
63 Expect.equals(123456789012345678900, a * b); 67 Expect.equals(123456789012345678900, a * b);
64 Expect.equals(123456789012345678900, b * a); 68 Expect.equals(123456789012345678900, b * a);
65 // Bigint and Bigint. 69 // Bigint and Bigint.
66 a = 12345678901234567890; 70 a = 12345678901234567890;
67 b = 10000000000000000; 71 b = 10000000000000000;
68 Expect.equals(123456789012345678900000000000000000, a * b); 72 Expect.equals(123456789012345678900000000000000000, a * b);
69 // Bigint and double. 73 // Bigint and double.
70 a = 200.0; 74 a = 2.0;
71 b = 100000000000; 75 b = 200000000000000000000;
72 Expect.equals(20000000000000.0, a * b); 76 Expect.isTrue((a * b) is double);
73 Expect.equals(20000000000000.0, b * a); 77 Expect.equals(400000000000000000000.0, a * b);
78 Expect.isTrue((b * a) is double);
79 Expect.equals(400000000000000000000.0, b * a);
74 } 80 }
75 81
76 static testBigintHugeMul() { 82 static testBigintHugeMul() {
77 var block = 28 * 256; // 28 bit chunks with 8 bit 'carry' in a DoubleChunk . 83 var block = 28 * 256; // 28 bit chunks with 8 bit 'carry' in a DoubleChunk .
78 var bits = block * 32; // plenty of blocks in longest column sum; 84 var bits = block * 32; // plenty of blocks in longest column sum;
79 var a = 1 << bits; 85 var a = 1 << bits;
80 var a1 = a - 1; // all 1's 86 var a1 = a - 1; // all 1's
81 var p1 = a1 * a1; 87 var p1 = a1 * a1;
82 var p2 = a * a - a - a + 1; 88 var p2 = a * a - a - a + 1;
83 // Use isTrue instead of equals to avoid trying to print such big numbers. 89 // Use isTrue instead of equals to avoid trying to print such big numbers.
84 Expect.isTrue(p1 == p2, 'products do not match'); 90 Expect.isTrue(p1 == p2, 'products do not match');
85 } 91 }
86 92
87 static testBigintTruncDiv() { 93 static testBigintTruncDiv() {
88 var a = 12345678901234567890; 94 var a = 12345678901234567890;
89 var b = 10; 95 var b = 10;
90 // Bigint and Smi. 96 // Bigint and Smi.
91 Expect.equals(1234567890123456789, a ~/ b); 97 Expect.equals(1234567890123456789, a ~/ b);
92 Expect.equals(0, b ~/ a); 98 Expect.equals(0, b ~/ a);
93 Expect.equals(123456789, 123456789012345678 ~/ 1000000000); 99 Expect.equals(123456789, 123456789012345678 ~/ 1000000000);
94 // Bigint and Bigint. 100 // Bigint and Bigint.
95 a = 12345678901234567890; 101 a = 12345678901234567890;
96 b = 10000000000000000; 102 b = 10000000000000000;
97 Expect.equals(1234, a ~/ b); 103 Expect.equals(1234, a ~/ b);
98 // Bigint and double. 104 // Bigint and double.
99 a = 200.0; 105 a = 100000000000000000000.0;
100 b = 100000000000; 106 b = 200000000000000000000;
101 Expect.equals(0.0, a ~/ b); 107 Expect.equals(0, a ~/ b);
102 Expect.equals(500000000.0, b ~/ a); 108 Expect.equals(2, b ~/ a);
103 } 109 }
104 110
105 static testBigintDiv() { 111 static testBigintDiv() {
106 // Bigint and Smi. 112 // Bigint and Smi.
107 Expect.equals(1234567890123456789.1, 12345678901234567891 / 10); 113 Expect.equals(1234567890123456789.1, 12345678901234567891 / 10);
108 Expect.equals(0.000000001234, 1234 / 1000000000000); 114 Expect.equals(0.000000001234, 1234 / 1000000000000);
109 Expect.equals(12345678901234000000.0, 123456789012340000000 / 10); 115 Expect.equals(12345678901234000000.0, 123456789012340000000 / 10);
110 // Bigint and Bigint. 116 // Bigint and Bigint.
111 var a = 12345670000000000000; 117 var a = 12345670000000000000;
112 var b = 10000000000000000; 118 var b = 10000000000000000;
113 Expect.equals(1234.567, a / b); 119 Expect.equals(1234.567, a / b);
114 // Bigint and double. 120 // Bigint and double.
115 a = 200.0; 121 a = 400000000000000000000.0;
116 b = 100000000000; 122 b = 200000000000000000000;
117 Expect.equals(0.000000002, a / b); 123 Expect.equals(2.0, a / b);
118 Expect.equals(500000000.0, b / a); 124 Expect.equals(0.5, b / a);
119 } 125 }
120 126
121 static testBigintModulo() { 127 static testBigintModulo() {
122 // Bigint and Smi. 128 // Bigint and Smi.
123 var a = 1000000000005; 129 var a = 1000000000005;
124 var b = 10; 130 var b = 10;
125 Expect.equals(5, a % b); 131 Expect.equals(5, a % b);
126 Expect.equals(10, b % a); 132 Expect.equals(10, b % a);
127 // Bigint & Bigint 133 // Bigint & Bigint
128 a = 10000000000000000001; 134 a = 10000000000000000001;
129 b = 10000000000000000000; 135 b = 10000000000000000000;
130 Expect.equals(1, a % b); 136 Expect.equals(1, a % b);
131 Expect.equals(10000000000000000000, b % a); 137 Expect.equals(10000000000000000000, b % a);
132 // Bigint & double. 138 // Bigint & double.
133 a = 100000000001.0; 139 a = 10000000100000000.0;
134 b = 100000000000; 140 b = 10000000000000000;
135 Expect.equals(1.0, a % b); 141 Expect.equals(100000000.0, a % b);
136 Expect.equals(100000000000.0, b % a); 142 Expect.equals(10000000000000000.0, b % a);
137 // Transitioning from Mint to Bigint. 143 // Transitioning from Mint to Bigint.
138 var iStart = 4611686018427387900; 144 var iStart = 4611686018427387900;
139 var prevX = -23 % iStart; 145 var prevX = -23 % iStart;
140 for (int i = iStart + 1; i < iStart + 10; i++) { 146 for (int i = iStart + 1; i < iStart + 10; i++) {
141 var x = -23 % i; 147 var x = -23 % i;
142 Expect.equals(1, x - prevX); 148 Expect.equals(1, x - prevX);
143 Expect.isTrue(x > 0); 149 Expect.isTrue(x > 0);
144 prevX = x; 150 prevX = x;
145 } 151 }
146 } 152 }
147 153
148 static testBigintNegate() { 154 static testBigintNegate() {
149 var a = 0xF000000000F; 155 var a = 0xF000000000000000F;
150 var b = ~a; // negate. 156 var b = ~a; // negate.
151 Expect.equals(-0xF0000000010, b); 157 Expect.equals(-0xF0000000000000010, b);
152 Expect.equals(0, a & b); 158 Expect.equals(0, a & b);
153 Expect.equals(-1, a | b); 159 Expect.equals(-1, a | b);
154 } 160 }
155 161
156 static testShiftAmount() { 162 static testShiftAmount() {
157 Expect.equals(0, 12 >> 111111111111111111111111111111); 163 Expect.equals(0, 12 >> 111111111111111111111111111111);
158 Expect.equals(-1, -12 >> 111111111111111111111111111111); 164 Expect.equals(-1, -12 >> 111111111111111111111111111111);
159 bool exceptionCaught = false; 165 bool exceptionCaught = false;
160 try { 166 try {
161 var a = 1 << 1111111111111111111111111111; 167 var a = 1 << 1111111111111111111111111111;
(...skipping 20 matching lines...) Expand all
182 var a = 10000000000000000000; 188 var a = 10000000000000000000;
183 var b = 10000000000000000001; 189 var b = 10000000000000000001;
184 Expect.equals(false, a.hashCode == b.hashCode); 190 Expect.equals(false, a.hashCode == b.hashCode);
185 Expect.equals(true, a.hashCode == (b - 1).hashCode); 191 Expect.equals(true, a.hashCode == (b - 1).hashCode);
186 } 192 }
187 } 193 }
188 194
189 main() { 195 main() {
190 BigIntegerTest.testMain(); 196 BigIntegerTest.testMain();
191 } 197 }
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698