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

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

Issue 24372002: Int32, Int64 default constructor now takes an optional int parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/fixnum/pubspec.yaml ('k') | pkg/fixnum/test/int_64_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fixnum/test/int_32_test.dart
diff --git a/pkg/fixnum/test/int_32_test.dart b/pkg/fixnum/test/int_32_test.dart
index 401f5333599e325faa1f74013a941c02ad6f6bec..1fcaed05c0774054e17c2b309cb731a34e53d917 100644
--- a/pkg/fixnum/test/int_32_test.dart
+++ b/pkg/fixnum/test/int_32_test.dart
@@ -8,245 +8,239 @@ import 'package:unittest/unittest.dart';
void main() {
group("arithmetic operators", () {
- Int32 n1 = new Int32.fromInt(1234);
- Int32 n2 = new Int32.fromInt(9876);
- Int32 n3 = new Int32.fromInt(-1234);
- Int32 n4 = new Int32.fromInt(-9876);
- Int32 n5 = new Int32.fromInt(0x12345678);
- Int32 n6 = new Int32.fromInt(0x22222222);
+ Int32 n1 = new Int32(1234);
+ Int32 n2 = new Int32(9876);
+ Int32 n3 = new Int32(-1234);
+ Int32 n4 = new Int32(-9876);
+ Int32 n5 = new Int32(0x12345678);
+ Int32 n6 = new Int32(0x22222222);
test("+", () {
- expect(n1 + n2, new Int32.fromInt(11110));
- expect(n3 + n2, new Int32.fromInt(8642));
- expect(n3 + n4, new Int32.fromInt(-11110));
+ expect(n1 + n2, new Int32(11110));
+ expect(n3 + n2, new Int32(8642));
+ expect(n3 + n4, new Int32(-11110));
expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE);
- expect(() => new Int32.fromInt(17) + null, throws);
+ expect(() => new Int32(17) + null, throws);
});
test("-", () {
- expect(n1 - n2, new Int32.fromInt(-8642));
- expect(n3 - n2, new Int32.fromInt(-11110));
- expect(n3 - n4, new Int32.fromInt(8642));
+ expect(n1 - n2, new Int32(-8642));
+ expect(n3 - n2, new Int32(-11110));
+ expect(n3 - n4, new Int32(8642));
expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE);
- expect(() => new Int32.fromInt(17) - null, throws);
+ expect(() => new Int32(17) - null, throws);
});
test("unary -", () {
- expect(-n1, new Int32.fromInt(-1234));
+ expect(-n1, new Int32(-1234));
expect(-Int32.ZERO, Int32.ZERO);
});
test("*", () {
- expect(n1 * n2, new Int32.fromInt(12186984));
- expect(n2 * n3, new Int32.fromInt(-12186984));
- expect(n3 * n3, new Int32.fromInt(1522756));
- expect(n3 * n2, new Int32.fromInt(-12186984));
- expect(new Int32.fromInt(0x12345678) * new Int32.fromInt(0x22222222),
- new Int32.fromInt(-899716112));
- expect((new Int32.fromInt(123456789) * new Int32.fromInt(987654321)),
- new Int32.fromInt(-67153019));
- expect(new Int32.fromInt(0x12345678) * new Int64.fromInt(0x22222222),
+ expect(n1 * n2, new Int32(12186984));
+ expect(n2 * n3, new Int32(-12186984));
+ expect(n3 * n3, new Int32(1522756));
+ expect(n3 * n2, new Int32(-12186984));
+ expect(new Int32(0x12345678) * new Int32(0x22222222),
+ new Int32(-899716112));
+ expect((new Int32(123456789) * new Int32(987654321)),
+ new Int32(-67153019));
+ expect(new Int32(0x12345678) * new Int64(0x22222222),
new Int64.fromInts(0x026D60DC, 0xCA5F6BF0));
- expect((new Int32.fromInt(123456789) * 987654321),
- new Int32.fromInt(-67153019));
- expect(() => new Int32.fromInt(17) * null, throws);
+ expect((new Int32(123456789) * 987654321),
+ new Int32(-67153019));
+ expect(() => new Int32(17) * null, throws);
});
test("~/", () {
- expect(new Int32.fromInt(829893893) ~/ new Int32.fromInt(1919),
- new Int32.fromInt(432461));
- expect(new Int32.fromInt(0x12345678) ~/ new Int32.fromInt(0x22),
- new Int32.fromInt(0x12345678 ~/ 0x22));
- expect(new Int32.fromInt(829893893) ~/ new Int64.fromInt(1919),
- new Int32.fromInt(432461));
- expect(new Int32.fromInt(0x12345678) ~/ new Int64.fromInt(0x22),
- new Int32.fromInt(0x12345678 ~/ 0x22));
- expect(new Int32.fromInt(829893893) ~/ 1919, new Int32.fromInt(432461));
- expect(() => new Int32.fromInt(17) ~/ Int32.ZERO, throws);
- expect(() => new Int32.fromInt(17) ~/ null, throws);
+ expect(new Int32(829893893) ~/ new Int32(1919), new Int32(432461));
+ expect(new Int32(0x12345678) ~/ new Int32(0x22),
+ new Int32(0x12345678 ~/ 0x22));
+ expect(new Int32(829893893) ~/ new Int64(1919), new Int32(432461));
+ expect(new Int32(0x12345678) ~/ new Int64(0x22),
+ new Int32(0x12345678 ~/ 0x22));
+ expect(new Int32(829893893) ~/ 1919, new Int32(432461));
+ expect(() => new Int32(17) ~/ Int32.ZERO, throws);
+ expect(() => new Int32(17) ~/ null, throws);
});
test("%", () {
- expect(new Int32.fromInt(0x12345678) % new Int32.fromInt(0x22),
- new Int32.fromInt(0x12345678 % 0x22));
- expect(new Int32.fromInt(0x12345678) % new Int64.fromInt(0x22),
- new Int32.fromInt(0x12345678 % 0x22));
- expect(() => new Int32.fromInt(17) % null, throws);
+ expect(new Int32(0x12345678) % new Int32(0x22),
+ new Int32(0x12345678 % 0x22));
+ expect(new Int32(0x12345678) % new Int64(0x22),
+ new Int32(0x12345678 % 0x22));
+ expect(() => new Int32(17) % null, throws);
});
test("remainder", () {
- expect(new Int32.fromInt(0x12345678).remainder(new Int32.fromInt(0x22)),
- new Int32.fromInt(0x12345678.remainder(0x22)));
- expect(new Int32.fromInt(0x12345678).remainder(new Int32.fromInt(-0x22)),
- new Int32.fromInt(0x12345678.remainder(-0x22)));
- expect(new Int32.fromInt(-0x12345678).remainder(new Int32.fromInt(-0x22)),
- new Int32.fromInt(-0x12345678.remainder(-0x22)));
- expect(new Int32.fromInt(-0x12345678).remainder(new Int32.fromInt(0x22)),
- new Int32.fromInt(-0x12345678.remainder(0x22)));
- expect(new Int32.fromInt(0x12345678).remainder(new Int64.fromInt(0x22)),
- new Int32.fromInt(0x12345678.remainder(0x22)));
- expect(() => new Int32.fromInt(17).remainder(null), throws);
+ expect(new Int32(0x12345678).remainder(new Int32(0x22)),
+ new Int32(0x12345678.remainder(0x22)));
+ expect(new Int32(0x12345678).remainder(new Int32(-0x22)),
+ new Int32(0x12345678.remainder(-0x22)));
+ expect(new Int32(-0x12345678).remainder(new Int32(-0x22)),
+ new Int32(-0x12345678.remainder(-0x22)));
+ expect(new Int32(-0x12345678).remainder(new Int32(0x22)),
+ new Int32(-0x12345678.remainder(0x22)));
+ expect(new Int32(0x12345678).remainder(new Int64(0x22)),
+ new Int32(0x12345678.remainder(0x22)));
+ expect(() => new Int32(17).remainder(null), throws);
});
});
group("comparison operators", () {
test("<", () {
- expect(new Int32.fromInt(17) < new Int32.fromInt(18), true);
- expect(new Int32.fromInt(17) < new Int32.fromInt(17), false);
- expect(new Int32.fromInt(17) < new Int32.fromInt(16), false);
- expect(new Int32.fromInt(17) < new Int64.fromInt(18), true);
- expect(new Int32.fromInt(17) < new Int64.fromInt(17), false);
- expect(new Int32.fromInt(17) < new Int64.fromInt(16), false);
+ expect(new Int32(17) < new Int32(18), true);
+ expect(new Int32(17) < new Int32(17), false);
+ expect(new Int32(17) < new Int32(16), false);
+ expect(new Int32(17) < new Int64(18), true);
+ expect(new Int32(17) < new Int64(17), false);
+ expect(new Int32(17) < new Int64(16), false);
expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false);
- expect(() => new Int32.fromInt(17) < null, throws);
+ expect(() => new Int32(17) < null, throws);
});
test("<=", () {
- expect(new Int32.fromInt(17) <= new Int32.fromInt(18), true);
- expect(new Int32.fromInt(17) <= new Int32.fromInt(17), true);
- expect(new Int32.fromInt(17) <= new Int32.fromInt(16), false);
- expect(new Int32.fromInt(17) <= new Int64.fromInt(18), true);
- expect(new Int32.fromInt(17) <= new Int64.fromInt(17), true);
- expect(new Int32.fromInt(17) <= new Int64.fromInt(16), false);
+ expect(new Int32(17) <= new Int32(18), true);
+ expect(new Int32(17) <= new Int32(17), true);
+ expect(new Int32(17) <= new Int32(16), false);
+ expect(new Int32(17) <= new Int64(18), true);
+ expect(new Int32(17) <= new Int64(17), true);
+ expect(new Int32(17) <= new Int64(16), false);
expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false);
- expect(() => new Int32.fromInt(17) <= null, throws);
+ expect(() => new Int32(17) <= null, throws);
});
test("==", () {
- expect(new Int32.fromInt(17) == new Int32.fromInt(18), false);
- expect(new Int32.fromInt(17) == new Int32.fromInt(17), true);
- expect(new Int32.fromInt(17) == new Int32.fromInt(16), false);
- expect(new Int32.fromInt(17) == new Int64.fromInt(18), false);
- expect(new Int32.fromInt(17) == new Int64.fromInt(17), true);
- expect(new Int32.fromInt(17) == new Int64.fromInt(16), false);
+ expect(new Int32(17) == new Int32(18), false);
+ expect(new Int32(17) == new Int32(17), true);
+ expect(new Int32(17) == new Int32(16), false);
+ expect(new Int32(17) == new Int64(18), false);
+ expect(new Int32(17) == new Int64(17), true);
+ expect(new Int32(17) == new Int64(16), false);
expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false);
- expect(new Int32.fromInt(17) == new Object(), false);
- expect(new Int32.fromInt(17) == null, false);
+ expect(new Int32(17) == new Object(), false);
+ expect(new Int32(17) == null, false);
});
test(">=", () {
- expect(new Int32.fromInt(17) >= new Int32.fromInt(18), false);
- expect(new Int32.fromInt(17) >= new Int32.fromInt(17), true);
- expect(new Int32.fromInt(17) >= new Int32.fromInt(16), true);
- expect(new Int32.fromInt(17) >= new Int64.fromInt(18), false);
- expect(new Int32.fromInt(17) >= new Int64.fromInt(17), true);
- expect(new Int32.fromInt(17) >= new Int64.fromInt(16), true);
+ expect(new Int32(17) >= new Int32(18), false);
+ expect(new Int32(17) >= new Int32(17), true);
+ expect(new Int32(17) >= new Int32(16), true);
+ expect(new Int32(17) >= new Int64(18), false);
+ expect(new Int32(17) >= new Int64(17), true);
+ expect(new Int32(17) >= new Int64(16), true);
expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true);
- expect(() => new Int32.fromInt(17) >= null, throws);
+ expect(() => new Int32(17) >= null, throws);
});
test(">", () {
- expect(new Int32.fromInt(17) > new Int32.fromInt(18), false);
- expect(new Int32.fromInt(17) > new Int32.fromInt(17), false);
- expect(new Int32.fromInt(17) > new Int32.fromInt(16), true);
- expect(new Int32.fromInt(17) > new Int64.fromInt(18), false);
- expect(new Int32.fromInt(17) > new Int64.fromInt(17), false);
- expect(new Int32.fromInt(17) > new Int64.fromInt(16), true);
+ expect(new Int32(17) > new Int32(18), false);
+ expect(new Int32(17) > new Int32(17), false);
+ expect(new Int32(17) > new Int32(16), true);
+ expect(new Int32(17) > new Int64(18), false);
+ expect(new Int32(17) > new Int64(17), false);
+ expect(new Int32(17) > new Int64(16), true);
expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true);
- expect(() => new Int32.fromInt(17) > null, throws);
+ expect(() => new Int32(17) > null, throws);
});
});
group("bitwise operators", () {
test("&", () {
- expect(new Int32.fromInt(0x12345678) & new Int32.fromInt(0x22222222),
- new Int32.fromInt(0x12345678 & 0x22222222));
- expect(new Int32.fromInt(0x12345678) & new Int64.fromInt(0x22222222),
- new Int64.fromInt(0x12345678 & 0x22222222));
- expect(() => new Int32.fromInt(17) & null, throwsArgumentError);
+ expect(new Int32(0x12345678) & new Int32(0x22222222),
+ new Int32(0x12345678 & 0x22222222));
+ expect(new Int32(0x12345678) & new Int64(0x22222222),
+ new Int64(0x12345678 & 0x22222222));
+ expect(() => new Int32(17) & null, throwsArgumentError);
});
test("|", () {
- expect(new Int32.fromInt(0x12345678) | new Int32.fromInt(0x22222222),
- new Int32.fromInt(0x12345678 | 0x22222222));
- expect(new Int32.fromInt(0x12345678) | new Int64.fromInt(0x22222222),
- new Int64.fromInt(0x12345678 | 0x22222222));
- expect(() => new Int32.fromInt(17) | null, throws);
+ expect(new Int32(0x12345678) | new Int32(0x22222222),
+ new Int32(0x12345678 | 0x22222222));
+ expect(new Int32(0x12345678) | new Int64(0x22222222),
+ new Int64(0x12345678 | 0x22222222));
+ expect(() => new Int32(17) | null, throws);
});
test("^", () {
- expect(new Int32.fromInt(0x12345678) ^ new Int32.fromInt(0x22222222),
- new Int32.fromInt(0x12345678 ^ 0x22222222));
- expect(new Int32.fromInt(0x12345678) ^ new Int64.fromInt(0x22222222),
- new Int64.fromInt(0x12345678 ^ 0x22222222));
- expect(() => new Int32.fromInt(17) ^ null, throws);
+ expect(new Int32(0x12345678) ^ new Int32(0x22222222),
+ new Int32(0x12345678 ^ 0x22222222));
+ expect(new Int32(0x12345678) ^ new Int64(0x22222222),
+ new Int64(0x12345678 ^ 0x22222222));
+ expect(() => new Int32(17) ^ null, throws);
});
test("~", () {
- expect(~(new Int32.fromInt(0x12345678)), new Int32.fromInt(~0x12345678));
- expect(-(new Int32.fromInt(0x12345678)), new Int64.fromInt(-0x12345678));
+ expect(~(new Int32(0x12345678)), new Int32(~0x12345678));
+ expect(-(new Int32(0x12345678)), new Int64(-0x12345678));
});
});
group("bitshift operators", () {
test("<<", () {
- expect(new Int32.fromInt(0x12345678) << 7,
- new Int32.fromInt(0x12345678 << 7));
- expect(() => new Int32.fromInt(17) << -1, throwsArgumentError);
- expect(() => new Int32.fromInt(17) << null, throws);
+ expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7));
+ expect(() => new Int32(17) << -1, throwsArgumentError);
+ expect(() => new Int32(17) << null, throws);
});
test(">>", () {
- expect(new Int32.fromInt(0x12345678) >> 7,
- new Int32.fromInt(0x12345678 >> 7));
- expect(() => new Int32.fromInt(17) >> -1, throwsArgumentError);
- expect(() => new Int32.fromInt(17) >> null, throws);
+ expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7));
+ expect(() => new Int32(17) >> -1, throwsArgumentError);
+ expect(() => new Int32(17) >> null, throws);
});
test("shiftRightUnsigned", () {
- expect(new Int32.fromInt(0x12345678).shiftRightUnsigned(7),
- new Int32.fromInt(0x12345678 >> 7));
- expect(() => (new Int32.fromInt(17).shiftRightUnsigned(-1)),
- throwsArgumentError);
- expect(() => (new Int32.fromInt(17).shiftRightUnsigned(null)), throws);
+ expect(new Int32(0x12345678).shiftRightUnsigned(7),
+ new Int32(0x12345678 >> 7));
+ expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
+ expect(() => (new Int32(17).shiftRightUnsigned(null)), throws);
});
});
group("type conversions", () {
- expect(new Int32.fromInt(17).toInt(), 17);
- expect(new Int32.fromInt(-17).toInt(), -17);
- expect(new Int32.fromInt(17).toInt32(), new Int32.fromInt(17));
- expect(new Int32.fromInt(-17).toInt32(), new Int32.fromInt(-17));
- expect(new Int32.fromInt(17).toInt64(), new Int64.fromInt(17));
- expect(new Int32.fromInt(-17).toInt64(), new Int64.fromInt(-17));
+ expect(new Int32(17).toInt(), 17);
+ expect(new Int32(-17).toInt(), -17);
+ expect(new Int32(17).toInt32(), new Int32(17));
+ expect(new Int32(-17).toInt32(), new Int32(-17));
+ expect(new Int32(17).toInt64(), new Int64(17));
+ expect(new Int32(-17).toInt64(), new Int64(-17));
});
group("string representation", () {
test("toString", () {
- expect(new Int32.fromInt(0).toString(), "0");
- expect(new Int32.fromInt(1).toString(), "1");
- expect(new Int32.fromInt(-1).toString(), "-1");
- expect(new Int32.fromInt(1000).toString(), "1000");
- expect(new Int32.fromInt(-1000).toString(), "-1000");
- expect(new Int32.fromInt(123456789).toString(), "123456789");
- expect(new Int32.fromInt(2147483647).toString(), "2147483647");
- expect(new Int32.fromInt(2147483648).toString(), "-2147483648");
- expect(new Int32.fromInt(2147483649).toString(), "-2147483647");
- expect(new Int32.fromInt(2147483650).toString(), "-2147483646");
- expect(new Int32.fromInt(-2147483648).toString(), "-2147483648");
- expect(new Int32.fromInt(-2147483649).toString(), "2147483647");
- expect(new Int32.fromInt(-2147483650).toString(), "2147483646");
+ expect(new Int32(0).toString(), "0");
+ expect(new Int32(1).toString(), "1");
+ expect(new Int32(-1).toString(), "-1");
+ expect(new Int32(1000).toString(), "1000");
+ expect(new Int32(-1000).toString(), "-1000");
+ expect(new Int32(123456789).toString(), "123456789");
+ expect(new Int32(2147483647).toString(), "2147483647");
+ expect(new Int32(2147483648).toString(), "-2147483648");
+ expect(new Int32(2147483649).toString(), "-2147483647");
+ expect(new Int32(2147483650).toString(), "-2147483646");
+ expect(new Int32(-2147483648).toString(), "-2147483648");
+ expect(new Int32(-2147483649).toString(), "2147483647");
+ expect(new Int32(-2147483650).toString(), "2147483646");
});
});
group("toHexString", () {
test("returns hexadecimal string representation", () {
- expect(new Int32.fromInt(-1).toHexString(), "-1");
- expect((new Int32.fromInt(-1) >> 8).toHexString(), "-1");
- expect((new Int32.fromInt(-1) << 8).toHexString(), "-100");
- expect(new Int32.fromInt(123456789).toHexString(), "75bcd15");
- expect(new Int32.fromInt(-1).shiftRightUnsigned(8).toHexString(),
- "ffffff");
+ expect(new Int32(-1).toHexString(), "-1");
+ expect((new Int32(-1) >> 8).toHexString(), "-1");
+ expect((new Int32(-1) << 8).toHexString(), "-100");
+ expect(new Int32(123456789).toHexString(), "75bcd15");
+ expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff");
});
});
group("toRadixString", () {
test("returns base n string representation", () {
- expect(new Int32.fromInt(123456789).toRadixString(5), "223101104124");
+ expect(new Int32(123456789).toRadixString(5), "223101104124");
});
});
}
« no previous file with comments | « pkg/fixnum/pubspec.yaml ('k') | pkg/fixnum/test/int_64_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698