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 // A test to compare the results of the fixnum library with the Dart VM | 5 // A test to compare the results of the fixnum library with the Dart VM |
6 | 6 |
7 #library('int64vmtest'); | 7 #library('int64vmtest'); |
8 #import('dart:math', prefix: 'Math'); | 8 #import('dart:math', prefix: 'Math'); |
9 #source('../intx.dart'); | 9 #source('../intx.dart'); |
10 #source('../int32.dart'); | 10 #source('../int32.dart'); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 void _doTestUnary(UnaryOp op, int64 val) { | 183 void _doTestUnary(UnaryOp op, int64 val) { |
184 int ref = op.ref(val.toInt()); | 184 int ref = op.ref(val.toInt()); |
185 int64 result64 = op.test(val); | 185 int64 result64 = op.test(val); |
186 int result = result64.toInt(); | 186 int result = result64.toInt(); |
187 if (ref != result) { | 187 if (ref != result) { |
188 Expect.fail("${op.name}: val = $val"); | 188 Expect.fail("${op.name}: val = $val"); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 void doTestUnary(UnaryOp op) { | 192 void doTestUnary(UnaryOp op) { |
193 print("Testing operator ${op.name}"); | 193 print("Testing operator ${op.name}"); |
194 for (int i = 0; i < TEST_VALUES.length; i++) { | 194 for (int i = 0; i < TEST_VALUES.length; i++) { |
195 _doTestUnary(op, TEST_VALUES[i]); | 195 _doTestUnary(op, TEST_VALUES[i]); |
196 } | 196 } |
197 for (int i = 0; i < RANDOM_TESTS; i++) { | 197 for (int i = 0; i < RANDOM_TESTS; i++) { |
198 int64 randomLong = _randomInt64(); | 198 int64 randomLong = _randomInt64(); |
199 _doTestUnary(op, randomLong); | 199 _doTestUnary(op, randomLong); |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 void _doTestBinary(BinaryOp op, int64 val0, int64 val1) { | 203 void _doTestBinary(BinaryOp op, int64 val0, int64 val1) { |
204 // print("Test val0 = $val0, val1 = $val1"); | 204 // print("Test val0 = $val0, val1 = $val1"); |
205 var refException = null; | 205 var refException = null; |
206 int ref = -1; | 206 int ref = -1; |
207 try { | 207 try { |
208 ref = op.ref(val0.toInt(), val1.toInt()); | 208 ref = op.ref(val0.toInt(), val1.toInt()); |
209 } catch (Exception e) { | 209 } on Exception catch (e) { |
210 refException = e; | 210 refException = e; |
211 } | 211 } |
212 var testException = null; | 212 var testException = null; |
213 int result = -2; | 213 int result = -2; |
214 int64 result64; | 214 int64 result64; |
215 try { | 215 try { |
216 int64 val0_save = new int64._copy(val0); | 216 int64 val0_save = new int64._copy(val0); |
217 int64 val1_save = new int64._copy(val1); | 217 int64 val1_save = new int64._copy(val1); |
218 result64 = op.test(val0, val1); | 218 result64 = op.test(val0, val1); |
219 result = result64.toInt(); | 219 result = result64.toInt(); |
220 if (val0 != val0_save) { | 220 if (val0 != val0_save) { |
221 print( | 221 print( |
222 "Test altered first argument val0 = $val0, val0_save = $val0_save"); | 222 "Test altered first argument val0 = $val0, val0_save = $val0_save"); |
223 } | 223 } |
224 if (val1 != val1_save) { | 224 if (val1 != val1_save) { |
225 print("Test altered second argument"); | 225 print("Test altered second argument"); |
226 } | 226 } |
227 } catch (Exception e) { | 227 } on Exception catch (e) { |
228 testException = e; | 228 testException = e; |
229 } | 229 } |
230 if (testException is IntegerDivisionByZeroException && | 230 if (testException is IntegerDivisionByZeroException && |
231 refException is IntegerDivisionByZeroException) { | 231 refException is IntegerDivisionByZeroException) { |
232 } else if (testException != null || refException != null) { | 232 } else if (testException != null || refException != null) { |
233 Expect.fail("${op.name}: val0 = $val0, val1 = $val1, " | 233 Expect.fail("${op.name}: val0 = $val0, val1 = $val1, " |
234 "testException = $testException, refException = $refException"); | 234 "testException = $testException, refException = $refException"); |
235 return; | 235 return; |
236 } else if (ref != result) { | 236 } else if (ref != result) { |
237 if ("%" == op.name && ref < 0) { | 237 if ("%" == op.name && ref < 0) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 317 } |
318 } | 318 } |
319 for (int i = 0; i < RANDOM_TESTS; i++) { | 319 for (int i = 0; i < RANDOM_TESTS; i++) { |
320 int64 randomLong = _randomInt64(); | 320 int64 randomLong = _randomInt64(); |
321 for (int shift = -64; shift <= 64; shift++) { | 321 for (int shift = -64; shift <= 64; shift++) { |
322 _doTestShift(op, randomLong, shift); | 322 _doTestShift(op, randomLong, shift); |
323 } | 323 } |
324 } | 324 } |
325 } | 325 } |
326 } | 326 } |
OLD | NEW |