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

Unified Diff: pkg/fixnum/test/int_64_vm_test.dart

Issue 19669002: Migrate fixnum tests to unittest. Fix int32 rollover bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/fixnum/test/int_64_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fixnum/test/int_64_vm_test.dart
diff --git a/pkg/fixnum/test/int_64_vm_test.dart b/pkg/fixnum/test/int_64_vm_test.dart
index b0a40a795c5359fae83fc8210cb1c1049a36e299..0dcbd9f94c183a0d112ffab7ae3c30a4c2e22b3c 100644
--- a/pkg/fixnum/test/int_64_vm_test.dart
+++ b/pkg/fixnum/test/int_64_vm_test.dart
@@ -6,14 +6,9 @@
library int64vmtest;
-import "package:expect/expect.dart";
import 'dart:math' as math;
justinfagnani 2013/07/18 19:13:48 this test is skipped, right? should it just be del
Chris Bracken 2013/07/18 19:38:08 Better to replace it with a well-defined set of de
-
-part 'package:fixnum/src/int32.dart';
-part 'package:fixnum/src/int64.dart';
-part 'package:fixnum/src/intx.dart';
-
-final random = new math.Random();
+import 'package:fixnum/fixnum.dart';
+import "package:unittest/unittest.dart";
void main() {
int64VMTest test = new int64VMTest();
@@ -27,7 +22,7 @@ void main() {
test.doTestUnary(new UnaryOp("~", (a) => ~a));
test.doTestShift(new ShiftOp("<<", (a, n) => a << (n & 63)));
test.doTestShift(new ShiftOp(">>", (a, n) => a >> (n & 63)));
- test.doTestBoolean(new BooleanOp("compareTo", (a, b) => a.compareTo(b)));
+ test.doTestComparison(new ComparisonOp("compareTo", (a, b) => a.compareTo(b)));
test.doTestBoolean(new BooleanOp("==", (a, b) => a == b));
test.doTestBoolean(new BooleanOp("!=", (a, b) => a != b));
test.doTestBoolean(new BooleanOp("<", (a, b) => a < b));
@@ -39,6 +34,7 @@ void main() {
test.doTestBinary(new BinaryOp("remainder", (a, b) => a.remainder(b)));
}
+final random = new math.Random();
const int DISCARD = 0;
int64 _randomInt64() {
@@ -101,6 +97,12 @@ class ShiftOp extends Op {
int64 test(int64 val0, int shift) => op(val0, shift);
}
+class ComparisonOp extends Op {
+ ComparisonOp(String name, Function op) : super(name, op);
+ int ref(int val0, int val1) => trunc64(op(val0, val1));
+ int test(int64 val0, int64 val1) => op(val0, val1);
+}
+
class int64VMTest {
static const int BASE_VALUES = 32;
static const int RANDOM_TESTS = 32;
@@ -108,18 +110,14 @@ class int64VMTest {
int64VMTest() {
Set<int64> testSet = new Set<int64>();
- for (int i = 0; i < BASE_VALUES; i++) {
+ for (int i = 0; i < 64; i++) {
testSet.add(new int64.fromInt(i));
testSet.add(new int64.fromInt(-i));
testSet.add(int64.MIN_VALUE + i);
testSet.add(int64.MAX_VALUE - i);
- testSet.add(new int64.fromInt(i << int64._BITS ~/ 2));
- testSet.add(new int64.fromInt(i << int64._BITS));
- testSet.add(new int64.fromInt(i << (3 * int64._BITS) ~/ 2));
- testSet.add(new int64.fromInt(i << 2 * int64._BITS));
- testSet.add(new int64.fromInt(i << (5 * int64._BITS) ~/ 2));
+ testSet.add(new int64.fromInt(0xf << i));
}
int64 one = new int64.fromInt(1);
@@ -189,9 +187,7 @@ class int64VMTest {
int ref = op.ref(val.toInt());
int64 result64 = op.test(val);
int result = result64.toInt();
- if (ref != result) {
- Expect.fail("${op.name}: val = $val");
- }
+ expect(ref == result, true, reason: "${op.name}: val = $val");
}
void doTestUnary(UnaryOp op) {
@@ -206,7 +202,6 @@ class int64VMTest {
}
void _doTestBinary(BinaryOp op, int64 val0, int64 val1) {
- // print("Test val0 = $val0, val1 = $val1");
var refException = null;
int ref = -1;
try {
@@ -218,16 +213,15 @@ class int64VMTest {
int result = -2;
int64 result64;
try {
- int64 val0_save = new int64._copy(val0);
- int64 val1_save = new int64._copy(val1);
+ int val0_save = val0.toInt();
+ int val1_save = val1.toInt();
result64 = op.test(val0, val1);
result = result64.toInt();
- if (val0 != val0_save) {
- print(
- "Test altered first argument val0 = $val0, val0_save = $val0_save");
+ if (val0.toInt() != val0_save) {
+ fail("Test altered val0 = $val0, val0_save = $val0_save");
}
- if (val1 != val1_save) {
- print("Test altered second argument");
+ if (val1.toInt() != val1_save) {
+ fail("Test altered val1 = $val1, val1_save = $val1_save");
}
} on Exception catch (e) {
testException = e;
@@ -235,16 +229,16 @@ class int64VMTest {
if (testException is IntegerDivisionByZeroException &&
refException is IntegerDivisionByZeroException) {
} else if (testException != null || refException != null) {
- Expect.fail("${op.name}: val0 = $val0, val1 = $val1, "
+ fail("${op.name}: val0 = $val0, val1 = $val1, "
"testException = $testException, refException = $refException");
return;
} else if (ref != result) {
if ("%" == op.name && ref < 0) {
- // print("Dart VM bug: ${op.name}: val0 = $val0, val1 = $val1, "
- // "ref = $ref, result64 = $result64, result = $result");
- } else {
- Expect.fail("${op.name}: val0 = $val0, val1 = $val1, "
+ fail("Dart VM bug: ${op.name}: val0 = $val0, val1 = $val1, "
"ref = $ref, result64 = $result64, result = $result");
+ } else {
+ fail("${op.name}: val0 = $val0, val1 = $val1, "
+ "ref = $ref, result64 = $result64, result = $result");
}
}
}
@@ -276,9 +270,8 @@ class int64VMTest {
void _doTestBoolean(BooleanOp op, int64 val0, int64 val1) {
bool ref = op.ref(val0.toInt(), val1.toInt());
bool result = op.test(val0, val1);
- if (ref != result) {
- Expect.fail("${op.name}: val0 = $val0, val1 = $val1");
- }
+ expect(ref == result, true,
+ reason: "${op.name}: val0 = $val0, val1 = $val1");
}
void doTestBoolean(BooleanOp op) {
@@ -305,13 +298,43 @@ class int64VMTest {
}
}
+ void _doTestComparison(ComparisonOp op, int64 val0, int64 val1) {
+ int ref = op.ref(val0.toInt(), val1.toInt());
+ int result = op.test(val0, val1);
+ expect(ref == result, true,
+ reason: "${op.name}: val0 = $val0, val1 = $val1");
+ }
+
+ void doTestComparison(ComparisonOp op) {
+ print("Testing operator ${op.name}");
+ for (int i = 0; i < TEST_VALUES.length; i++) {
+ int64 randomLong = _randomInt64();
+ _doTestComparison(op, TEST_VALUES[i], randomLong);
+ _doTestComparison(op, randomLong, TEST_VALUES[i]);
+ for (int j = 0; j < TEST_VALUES.length; j++) {
+ _doTestComparison(op, TEST_VALUES[i], TEST_VALUES[j]);
+ }
+ }
+ for (int i = 0; i < RANDOM_TESTS; i++) {
+ int64 longVal0 = _randomInt64();
+ int64 longVal1 = _randomInt64();
+ if (_randomInt(20) == 0) {
+ if (_randomInt(2) == 0) {
+ longVal1 = longVal0;
+ } else {
+ longVal1 = -longVal0;
+ }
+ }
+ _doTestComparison(op, longVal0, longVal1);
+ }
+ }
+
void _doTestShift(ShiftOp op, int64 val, int shift) {
int ref = op.ref(val.toInt(), shift);
int64 result64 = op.test(val, shift);
int result = result64.toInt();
- if (ref != result) {
- Expect.fail("${op.name}: val = $val, shift = $shift");
- }
+ expect(ref == result, true,
+ reason: "${op.name}: val = $val, shift = $shift");
}
void doTestShift(ShiftOp op) {
« 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