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

Side by Side Diff: pkg/fixnum/test/int_64_vm_test.dart

Issue 11405003: Update fixnum to new package guidelines. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « pkg/fixnum/test/int_64_test.dart ('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) 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 part '../intx.dart'; 9 part '../lib/intx.dart';
10 part '../int32.dart'; 10 part '../lib/int32.dart';
11 part '../int64.dart'; 11 part '../lib/int64.dart';
gram 2012/11/09 18:35:55 Won't you have a problem here later with 'part of'
Bob Nystrom 2012/11/09 21:23:17 Yeah, we will. I tried making them sublibraries in
12 12
13 void main() { 13 void main() {
14 int64VMTest test = new int64VMTest(); 14 int64VMTest test = new int64VMTest();
15 test.doTestBinary(new BinaryOp("&", (a, b) => a & b)); 15 test.doTestBinary(new BinaryOp("&", (a, b) => a & b));
16 test.doTestBinary(new BinaryOp("|", (a, b) => a | b)); 16 test.doTestBinary(new BinaryOp("|", (a, b) => a | b));
17 test.doTestBinary(new BinaryOp("^", (a, b) => a ^ b)); 17 test.doTestBinary(new BinaryOp("^", (a, b) => a ^ b));
18 test.doTestBinary(new BinaryOp("+", (a, b) => a + b)); 18 test.doTestBinary(new BinaryOp("+", (a, b) => a + b));
19 test.doTestBinary(new BinaryOp("-", (a, b) => a - b)); 19 test.doTestBinary(new BinaryOp("-", (a, b) => a - b));
20 test.doTestBinary(new BinaryOp("*", (a, b) => a * b)); 20 test.doTestBinary(new BinaryOp("*", (a, b) => a * b));
21 test.doTestUnary(new UnaryOp("-", (a) => -a)); 21 test.doTestUnary(new UnaryOp("-", (a) => -a));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 class ShiftOp extends Op { 93 class ShiftOp extends Op {
94 ShiftOp(String name, Function op) : super(name, op); 94 ShiftOp(String name, Function op) : super(name, op);
95 int ref(int val0, int shift) => trunc64(op(val0, shift)); 95 int ref(int val0, int shift) => trunc64(op(val0, shift));
96 int64 test(int64 val0, int shift) => op(val0, shift); 96 int64 test(int64 val0, int shift) => op(val0, shift);
97 } 97 }
98 98
99 class int64VMTest { 99 class int64VMTest {
100 static const int BASE_VALUES = 32; 100 static const int BASE_VALUES = 32;
101 static const int RANDOM_TESTS = 32; 101 static const int RANDOM_TESTS = 32;
102 List<int64> TEST_VALUES; 102 List<int64> TEST_VALUES;
103 103
104 int64VMTest() { 104 int64VMTest() {
105 Set<int64> testSet = new Set<int64>(); 105 Set<int64> testSet = new Set<int64>();
106 for (int i = 0; i < BASE_VALUES; i++) { 106 for (int i = 0; i < BASE_VALUES; i++) {
107 testSet.add(new int64.fromInt(i)); 107 testSet.add(new int64.fromInt(i));
108 testSet.add(new int64.fromInt(-i)); 108 testSet.add(new int64.fromInt(-i));
109 109
110 testSet.add(int64.MIN_VALUE + i); 110 testSet.add(int64.MIN_VALUE + i);
111 testSet.add(int64.MAX_VALUE - i); 111 testSet.add(int64.MAX_VALUE - i);
112 112
113 testSet.add(new int64.fromInt(i << int64._BITS ~/ 2)); 113 testSet.add(new int64.fromInt(i << int64._BITS ~/ 2));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 } 269 }
270 270
271 void _doTestBoolean(BooleanOp op, int64 val0, int64 val1) { 271 void _doTestBoolean(BooleanOp op, int64 val0, int64 val1) {
272 bool ref = op.ref(val0.toInt(), val1.toInt()); 272 bool ref = op.ref(val0.toInt(), val1.toInt());
273 bool result = op.test(val0, val1); 273 bool result = op.test(val0, val1);
274 if (ref != result) { 274 if (ref != result) {
275 Expect.fail("${op.name}: val0 = $val0, val1 = $val1"); 275 Expect.fail("${op.name}: val0 = $val0, val1 = $val1");
276 } 276 }
277 } 277 }
278 278
279 void doTestBoolean(BooleanOp op) { 279 void doTestBoolean(BooleanOp op) {
280 print("Testing operator ${op.name}"); 280 print("Testing operator ${op.name}");
281 for (int i = 0; i < TEST_VALUES.length; i++) { 281 for (int i = 0; i < TEST_VALUES.length; i++) {
282 int64 randomLong = _randomInt64(); 282 int64 randomLong = _randomInt64();
283 _doTestBoolean(op, TEST_VALUES[i], randomLong); 283 _doTestBoolean(op, TEST_VALUES[i], randomLong);
284 _doTestBoolean(op, randomLong, TEST_VALUES[i]); 284 _doTestBoolean(op, randomLong, TEST_VALUES[i]);
285 for (int j = 0; j < TEST_VALUES.length; j++) { 285 for (int j = 0; j < TEST_VALUES.length; j++) {
286 _doTestBoolean(op, TEST_VALUES[i], TEST_VALUES[j]); 286 _doTestBoolean(op, TEST_VALUES[i], TEST_VALUES[j]);
287 } 287 }
288 } 288 }
(...skipping 12 matching lines...) Expand all
301 } 301 }
302 302
303 void _doTestShift(ShiftOp op, int64 val, int shift) { 303 void _doTestShift(ShiftOp op, int64 val, int shift) {
304 int ref = op.ref(val.toInt(), shift); 304 int ref = op.ref(val.toInt(), shift);
305 int64 result64 = op.test(val, shift); 305 int64 result64 = op.test(val, shift);
306 int result = result64.toInt(); 306 int result = result64.toInt();
307 if (ref != result) { 307 if (ref != result) {
308 Expect.fail("${op.name}: val = $val, shift = $shift"); 308 Expect.fail("${op.name}: val = $val, shift = $shift");
309 } 309 }
310 } 310 }
311 311
312 void doTestShift(ShiftOp op) { 312 void doTestShift(ShiftOp op) {
313 print("Testing operator ${op.name}"); 313 print("Testing operator ${op.name}");
314 for (int i = 0; i < TEST_VALUES.length; i++) { 314 for (int i = 0; i < TEST_VALUES.length; i++) {
315 for (int shift = -64; shift <= 64; shift++) { 315 for (int shift = -64; shift <= 64; shift++) {
316 _doTestShift(op, TEST_VALUES[i], shift); 316 _doTestShift(op, TEST_VALUES[i], shift);
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 }
OLDNEW
« no previous file with comments | « pkg/fixnum/test/int_64_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698