Address pedantic lints (#52)
* Update int64.dart
* Update analysis_options.yaml
* Update int32.dart
* Update int64.dart
* Update int32.dart
* Update int32.dart
* Update intx.dart
* Update int32.dart
* Update all_tests.dart
* Update int32_test.dart
* Update pubspec.yaml
* Update int_64_vm_test.dart
* Update int64_test.dart
* Update int64_test.dart
* Update int64_test.dart
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 6ddb107..628d93e 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -4,7 +4,6 @@
implicit-casts: false
linter:
rules:
- #- annotate_overrides
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
@@ -30,7 +29,6 @@
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- non_constant_identifier_names
- #- omit_local_variable_types
- only_throw_errors
- overridden_fields
- package_api_docs
@@ -44,7 +42,6 @@
- prefer_generic_function_type_aliases
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- #- prefer_single_quotes
- prefer_typing_uninitialized_variables
- slash_for_doc_comments
- test_types_in_equals
@@ -57,4 +54,3 @@
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_statements
- #- unnecessary_this
diff --git a/lib/src/int32.dart b/lib/src/int32.dart
index 3a9d017..ec31d9d 100644
--- a/lib/src/int32.dart
+++ b/lib/src/int32.dart
@@ -54,12 +54,12 @@
// TODO(rice) - Make this faster by converting several digits at once.
static Int32 parseRadix(String s, int radix) {
_validateRadix(radix);
- Int32 x = ZERO;
- for (int i = 0; i < s.length; i++) {
- int c = s.codeUnitAt(i);
- int digit = _decodeDigit(c);
+ var x = ZERO;
+ for (var i = 0; i < s.length; i++) {
+ var c = s.codeUnitAt(i);
+ var digit = _decodeDigit(c);
if (digit < 0 || digit >= radix) {
- throw FormatException("Non-radix code unit: $c");
+ throw FormatException('Non-radix code unit: $c');
}
x = ((x * radix) + digit) as Int32;
}
@@ -145,76 +145,88 @@
// Int32 % Int32 => Int32
// Int32 % Int64 => Int32
+ @override
IntX operator +(other) {
if (other is Int64) {
- return this.toInt64() + other;
+ return toInt64() + other;
}
return Int32(_i + _toInt(other));
}
+ @override
IntX operator -(other) {
if (other is Int64) {
- return this.toInt64() - other;
+ return toInt64() - other;
}
return Int32(_i - _toInt(other));
}
+ @override
Int32 operator -() => Int32(-_i);
+ @override
IntX operator *(other) {
if (other is Int64) {
- return this.toInt64() * other;
+ return toInt64() * other;
}
// TODO(rice) - optimize
- return (this.toInt64() * other).toInt32();
+ return (toInt64() * other).toInt32();
}
+ @override
Int32 operator %(other) {
if (other is Int64) {
// Result will be Int32
- return (this.toInt64() % other).toInt32();
+ return (toInt64() % other).toInt32();
}
return Int32(_i % _toInt(other));
}
+ @override
Int32 operator ~/(other) {
if (other is Int64) {
- return (this.toInt64() ~/ other).toInt32();
+ return (toInt64() ~/ other).toInt32();
}
return Int32(_i ~/ _toInt(other));
}
+ @override
Int32 remainder(other) {
if (other is Int64) {
- Int64 t = this.toInt64();
+ var t = toInt64();
return (t - (t ~/ other) * other).toInt32();
}
return (this - (this ~/ other) * other) as Int32;
}
+ @override
Int32 operator &(other) {
if (other is Int64) {
- return (this.toInt64() & other).toInt32();
+ return (toInt64() & other).toInt32();
}
return Int32(_i & _toInt(other));
}
+ @override
Int32 operator |(other) {
if (other is Int64) {
- return (this.toInt64() | other).toInt32();
+ return (toInt64() | other).toInt32();
}
return Int32(_i | _toInt(other));
}
+ @override
Int32 operator ^(other) {
if (other is Int64) {
- return (this.toInt64() ^ other).toInt32();
+ return (toInt64() ^ other).toInt32();
}
return Int32(_i ^ _toInt(other));
}
+ @override
Int32 operator ~() => Int32(~_i);
+ @override
Int32 operator <<(int n) {
if (n < 0) {
throw ArgumentError(n);
@@ -225,6 +237,7 @@
return Int32(_i << n);
}
+ @override
Int32 operator >>(int n) {
if (n < 0) {
throw ArgumentError(n);
@@ -241,6 +254,7 @@
return Int32(value);
}
+ @override
Int32 shiftRightUnsigned(int n) {
if (n < 0) {
throw ArgumentError(n);
@@ -259,64 +273,86 @@
/// Returns [:true:] if this [Int32] has the same numeric value as the
/// given object. The argument may be an [int] or an [IntX].
+ @override
bool operator ==(other) {
if (other is Int32) {
return _i == other._i;
} else if (other is Int64) {
- return this.toInt64() == other;
+ return toInt64() == other;
} else if (other is int) {
return _i == other;
}
return false;
}
+ @override
int compareTo(other) {
if (other is Int64) {
- return this.toInt64().compareTo(other);
+ return toInt64().compareTo(other);
}
return _i.compareTo(_toInt(other));
}
+ @override
bool operator <(other) {
if (other is Int64) {
- return this.toInt64() < other;
+ return toInt64() < other;
}
return _i < _toInt(other);
}
+ @override
bool operator <=(other) {
if (other is Int64) {
- return this.toInt64() <= other;
+ return toInt64() <= other;
}
return _i <= _toInt(other);
}
+ @override
bool operator >(other) {
if (other is Int64) {
- return this.toInt64() > other;
+ return toInt64() > other;
}
return _i > _toInt(other);
}
+ @override
bool operator >=(other) {
if (other is Int64) {
- return this.toInt64() >= other;
+ return toInt64() >= other;
}
return _i >= _toInt(other);
}
+ @override
bool get isEven => (_i & 0x1) == 0;
+
+ @override
bool get isMaxValue => _i == 2147483647;
+
+ @override
bool get isMinValue => _i == -2147483648;
+
+ @override
bool get isNegative => _i < 0;
+
+ @override
bool get isOdd => (_i & 0x1) == 1;
+
+ @override
bool get isZero => _i == 0;
+
+ @override
int get bitLength => _i.bitLength;
+ @override
int get hashCode => _i;
+ @override
Int32 abs() => _i < 0 ? Int32(-_i) : this;
+ @override
Int32 clamp(lowerLimit, upperLimit) {
if (this < lowerLimit) {
if (lowerLimit is IntX) return lowerLimit.toInt32();
@@ -330,21 +366,27 @@
return this;
}
+ @override
int numberOfLeadingZeros() => _numberOfLeadingZeros(_i);
+
+ @override
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);
+ @override
Int32 toSigned(int width) {
if (width < 1 || width > 32) throw RangeError.range(width, 1, 32);
return Int32(_i.toSigned(width));
}
+ @override
Int32 toUnsigned(int width) {
if (width < 0 || width > 32) throw RangeError.range(width, 0, 32);
return Int32(_i.toUnsigned(width));
}
+ @override
List<int> toBytes() {
- List<int> result = List<int>(4);
+ var result = List<int>(4);
result[0] = _i & 0xff;
result[1] = (_i >> 8) & 0xff;
result[2] = (_i >> 16) & 0xff;
@@ -352,12 +394,24 @@
return result;
}
+ @override
double toDouble() => _i.toDouble();
+
+ @override
int toInt() => _i;
+
+ @override
Int32 toInt32() => this;
+
+ @override
Int64 toInt64() => Int64(_i);
+ @override
String toString() => _i.toString();
+
+ @override
String toHexString() => _i.toRadixString(16);
+
+ @override
String toRadixString(int radix) => _i.toRadixString(radix);
}
diff --git a/lib/src/int64.dart b/lib/src/int64.dart
index 3453a09..d624073 100644
--- a/lib/src/int64.dart
+++ b/lib/src/int64.dart
@@ -2,6 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// Many locals are declared as `int` or `double`. We keep local variable types
+// because the types are critical to the efficiency of many operations.
+//
+// ignore_for_file: omit_local_variable_types
+
part of fixnum;
/// An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1].
@@ -75,7 +80,7 @@
int c = s.codeUnitAt(i);
int digit = Int32._decodeDigit(c);
if (digit < 0 || digit >= radix) {
- throw FormatException("Non-radix char code: $c");
+ throw FormatException('Non-radix char code: $c');
}
// [radix] and [digit] are at most 6 bits, component is 22, so we can
@@ -192,6 +197,7 @@
throw ArgumentError.value(value);
}
+ @override
Int64 operator +(other) {
Int64 o = _promote(other);
int sum0 = _l + o._l;
@@ -200,13 +206,16 @@
return Int64._masked(sum0, sum1, sum2);
}
+ @override
Int64 operator -(other) {
Int64 o = _promote(other);
return _sub(_l, _m, _h, o._l, o._m, o._h);
}
+ @override
Int64 operator -() => _negate(_l, _m, _h);
+ @override
Int64 operator *(other) {
Int64 o = _promote(other);
@@ -288,12 +297,16 @@
return Int64._masked(c0, c1, c2);
}
+ @override
Int64 operator %(other) => _divide(this, other, _RETURN_MOD);
+ @override
Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV);
+ @override
Int64 remainder(other) => _divide(this, other, _RETURN_REM);
+ @override
Int64 operator &(other) {
Int64 o = _promote(other);
int a0 = _l & o._l;
@@ -302,6 +315,7 @@
return Int64._masked(a0, a1, a2);
}
+ @override
Int64 operator |(other) {
Int64 o = _promote(other);
int a0 = _l | o._l;
@@ -310,6 +324,7 @@
return Int64._masked(a0, a1, a2);
}
+ @override
Int64 operator ^(other) {
Int64 o = _promote(other);
int a0 = _l ^ o._l;
@@ -318,10 +333,12 @@
return Int64._masked(a0, a1, a2);
}
+ @override
Int64 operator ~() {
return Int64._masked(~_l, ~_m, ~_h);
}
+ @override
Int64 operator <<(int n) {
if (n < 0) {
throw ArgumentError.value(n);
@@ -348,6 +365,7 @@
return Int64._masked(res0, res1, res2);
}
+ @override
Int64 operator >>(int n) {
if (n < 0) {
throw ArgumentError.value(n);
@@ -393,6 +411,7 @@
return Int64._masked(res0, res1, res2);
}
+ @override
Int64 shiftRightUnsigned(int n) {
if (n < 0) {
throw ArgumentError.value(n);
@@ -422,6 +441,7 @@
/// Returns [:true:] if this [Int64] has the same numeric value as the
/// given object. The argument may be an [int] or an [IntX].
+ @override
bool operator ==(other) {
Int64 o;
if (other is Int64) {
@@ -441,6 +461,7 @@
return false;
}
+ @override
int compareTo(other) => _compareTo(other);
int _compareTo(other) {
@@ -468,18 +489,37 @@
return 0;
}
+ @override
bool operator <(other) => _compareTo(other) < 0;
+
+ @override
bool operator <=(other) => _compareTo(other) <= 0;
- bool operator >(other) => this._compareTo(other) > 0;
+
+ @override
+ bool operator >(other) => _compareTo(other) > 0;
+
+ @override
bool operator >=(other) => _compareTo(other) >= 0;
+ @override
bool get isEven => (_l & 0x1) == 0;
+
+ @override
bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK;
+
+ @override
bool get isMinValue => _h == _SIGN_BIT_MASK && _m == 0 && _l == 0;
+
+ @override
bool get isNegative => (_h & _SIGN_BIT_MASK) != 0;
+
+ @override
bool get isOdd => (_l & 0x1) == 1;
+
+ @override
bool get isZero => _h == 0 && _m == 0 && _l == 0;
+ @override
int get bitLength {
if (isZero) return 0;
int a0 = _l, a1 = _m, a2 = _h;
@@ -494,6 +534,7 @@
}
/// Returns a hash code based on all the bits of this [Int64].
+ @override
int get hashCode {
// TODO(sra): Should we ensure that hashCode values match corresponding int?
// i.e. should `new Int64(x).hashCode == x.hashCode`?
@@ -502,10 +543,12 @@
return bottom ^ top;
}
+ @override
Int64 abs() {
- return this.isNegative ? -this : this;
+ return isNegative ? -this : this;
}
+ @override
Int64 clamp(lowerLimit, upperLimit) {
Int64 lower = _promote(lowerLimit);
Int64 upper = _promote(upperLimit);
@@ -516,6 +559,7 @@
/// Returns the number of leading zeros in this [Int64] as an [int]
/// between 0 and 64.
+ @override
int numberOfLeadingZeros() {
int b2 = Int32._numberOfLeadingZeros(_h);
if (b2 == 32) {
@@ -532,6 +576,7 @@
/// Returns the number of trailing zeros in this [Int64] as an [int]
/// between 0 and 64.
+ @override
int numberOfTrailingZeros() {
int zeros = Int32._numberOfTrailingZeros(_l);
if (zeros < 32) {
@@ -551,6 +596,7 @@
return 64;
}
+ @override
Int64 toSigned(int width) {
if (width < 1 || width > 64) throw RangeError.range(width, 1, 64);
if (width > _BITS01) {
@@ -568,6 +614,7 @@
}
}
+ @override
Int64 toUnsigned(int width) {
if (width < 0 || width > 64) throw RangeError.range(width, 0, 64);
if (width > _BITS01) {
@@ -582,6 +629,7 @@
}
}
+ @override
List<int> toBytes() {
List<int> result = List<int>(8);
result[0] = _l & 0xff;
@@ -595,8 +643,10 @@
return result;
}
+ @override
double toDouble() => toInt().toDouble();
+ @override
int toInt() {
int l = _l;
int m = _m;
@@ -614,24 +664,28 @@
}
/// Returns an [Int32] containing the low 32 bits of this [Int64].
+ @override
Int32 toInt32() {
return Int32(((_m & 0x3ff) << _BITS) | _l);
}
/// Returns `this`.
+ @override
Int64 toInt64() => this;
/// Returns the value of this [Int64] as a decimal [String].
+ @override
String toString() => _toRadixString(10);
// TODO(rice) - Make this faster by avoiding arithmetic.
+ @override
String toHexString() {
- if (isZero) return "0";
+ if (isZero) return '0';
Int64 x = this;
- String hexStr = "";
+ String hexStr = '';
while (!x.isZero) {
int digit = x._l & 0xf;
- hexStr = "${_hexDigit(digit)}$hexStr";
+ hexStr = '${_hexDigit(digit)}$hexStr';
x = x.shiftRightUnsigned(4);
}
return hexStr;
@@ -648,6 +702,7 @@
return _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, '');
}
+ @override
String toRadixString(int radix) {
return _toRadixString(Int32._validateRadix(radix));
}
@@ -712,7 +767,7 @@
// need only two chunks, but radix values 17-19 and 33-36 generate only 15
// or 16 bits per iteration, so sometimes the third chunk is needed.
- String chunk1 = "", chunk2 = "", chunk3 = "";
+ String chunk1 = '', chunk2 = '', chunk3 = '';
while (!(d4 == 0 && d3 == 0)) {
int q = d4 ~/ fatRadix;
@@ -739,7 +794,7 @@
r = d0 - q * fatRadix;
d0 = q;
- assert(chunk3 == "");
+ assert(chunk3 == '');
chunk3 = chunk2;
chunk2 = chunk1;
// Adding [fatRadix] Forces an extra digit which we discard to get a fixed
@@ -814,7 +869,7 @@
];
String toDebugString() {
- return "Int64[_l=$_l, _m=$_m, _h=$_h]";
+ return 'Int64[_l=$_l, _m=$_m, _h=$_h]';
}
static Int64 _masked(int a0, int a1, int a2) =>
@@ -831,7 +886,7 @@
return _sub(0, 0, 0, b0, b1, b2);
}
- String _hexDigit(int digit) => "0123456789ABCDEF"[digit];
+ String _hexDigit(int digit) => '0123456789ABCDEF'[digit];
// Work around dart2js bugs with negative arguments to '>>' operator.
static int _shiftRight(int x, int n) {
diff --git a/lib/src/intx.dart b/lib/src/intx.dart
index cdc4b05..e1c1342 100644
--- a/lib/src/intx.dart
+++ b/lib/src/intx.dart
@@ -65,10 +65,12 @@
/// bits to the right. High-order bits are filled with zeros.
IntX shiftRightUnsigned(int shiftAmount);
+ @override
int compareTo(other);
/// Returns `true` if and only if [other] is an int or IntX equal in
/// value to this integer.
+ @override
bool operator ==(other);
/// Relational less than operator.
@@ -103,6 +105,7 @@
/// Returns `true` if and only if this integer is zero.
bool get isZero;
+ @override
int get hashCode;
/// Returns the absolute value of this integer.
@@ -179,6 +182,7 @@
/// Returns a string representing the value of this integer in decimal
/// notation; example: `'13'`.
+ @override
String toString();
/// Returns a string representing the value of this integer in hexadecimal
diff --git a/pubspec.yaml b/pubspec.yaml
index a08ee33..51c8708 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: fixnum
-version: 0.10.11
+version: 0.10.12-dev
description: Library for 32- and 64-bit signed fixed-width integers.
author: Dart Team <misc@dartlang.org>
diff --git a/test/all_tests.dart b/test/all_tests.dart
index a93d00b..eb530b7 100644
--- a/test/all_tests.dart
+++ b/test/all_tests.dart
@@ -1,7 +1,7 @@
import 'int32_test.dart' as int32_test;
import 'int64_test.dart' as int64_test;
-main() {
+void main() {
int32_test.main();
int64_test.main();
}
diff --git a/test/int32_test.dart b/test/int32_test.dart
index b9ba31a..db96123 100644
--- a/test/int32_test.dart
+++ b/test/int32_test.dart
@@ -6,40 +6,40 @@
import 'package:test/test.dart';
void main() {
- group("isX tests", () {
- test("isEven", () {
+ group('isX tests', () {
+ test('isEven', () {
expect((-Int32.ONE).isEven, false);
expect(Int32.ZERO.isEven, true);
expect(Int32.ONE.isEven, false);
expect(Int32.TWO.isEven, true);
});
- test("isMaxValue", () {
+ test('isMaxValue', () {
expect(Int32.MIN_VALUE.isMaxValue, false);
expect(Int32.ZERO.isMaxValue, false);
expect(Int32.MAX_VALUE.isMaxValue, true);
});
- test("isMinValue", () {
+ test('isMinValue', () {
expect(Int32.MIN_VALUE.isMinValue, true);
expect(Int32.ZERO.isMinValue, false);
expect(Int32.MAX_VALUE.isMinValue, false);
});
- test("isNegative", () {
+ test('isNegative', () {
expect(Int32.MIN_VALUE.isNegative, true);
expect(Int32.ZERO.isNegative, false);
expect(Int32.ONE.isNegative, false);
});
- test("isOdd", () {
+ test('isOdd', () {
expect((-Int32.ONE).isOdd, true);
expect(Int32.ZERO.isOdd, false);
expect(Int32.ONE.isOdd, true);
expect(Int32.TWO.isOdd, false);
});
- test("isZero", () {
+ test('isZero', () {
expect(Int32.MIN_VALUE.isZero, false);
expect(Int32.ZERO.isZero, true);
expect(Int32.MAX_VALUE.isZero, false);
});
- test("bitLength", () {
+ test('bitLength', () {
expect(Int32(-2).bitLength, 1);
expect((-Int32.ONE).bitLength, 0);
expect(Int32.ZERO.bitLength, 0);
@@ -50,13 +50,13 @@
});
});
- group("arithmetic operators", () {
- Int32 n1 = Int32(1234);
- Int32 n2 = Int32(9876);
- Int32 n3 = Int32(-1234);
- Int32 n4 = Int32(-9876);
+ group('arithmetic operators', () {
+ var n1 = Int32(1234);
+ var n2 = Int32(9876);
+ var n3 = Int32(-1234);
+ var n4 = Int32(-9876);
- test("+", () {
+ test('+', () {
expect(n1 + n2, Int32(11110));
expect(n3 + n2, Int32(8642));
expect(n3 + n4, Int32(-11110));
@@ -65,7 +65,7 @@
expect(() => Int32(17) + null, throwsArgumentError);
});
- test("-", () {
+ test('-', () {
expect(n1 - n2, Int32(-8642));
expect(n3 - n2, Int32(-11110));
expect(n3 - n4, Int32(8642));
@@ -74,12 +74,12 @@
expect(() => Int32(17) - null, throwsArgumentError);
});
- test("unary -", () {
+ test('unary -', () {
expect(-n1, Int32(-1234));
expect(-Int32.ZERO, Int32.ZERO);
});
- test("*", () {
+ test('*', () {
expect(n1 * n2, Int32(12186984));
expect(n2 * n3, Int32(-12186984));
expect(n3 * n3, Int32(1522756));
@@ -92,7 +92,7 @@
expect(() => Int32(17) * null, throwsArgumentError);
});
- test("~/", () {
+ test('~/', () {
expect(Int32(829893893) ~/ Int32(1919), Int32(432461));
expect(Int32(0x12345678) ~/ Int32(0x22), Int32(0x12345678 ~/ 0x22));
expect(Int32(829893893) ~/ Int64(1919), Int32(432461));
@@ -107,13 +107,13 @@
expect(() => Int32(17) ~/ null, throwsArgumentError);
});
- test("%", () {
+ test('%', () {
expect(Int32(0x12345678) % Int32(0x22), Int32(0x12345678 % 0x22));
expect(Int32(0x12345678) % Int64(0x22), Int32(0x12345678 % 0x22));
expect(() => Int32(17) % null, throwsArgumentError);
});
- test("remainder", () {
+ test('remainder', () {
expect(Int32(0x12345678).remainder(Int32(0x22)),
Int32(0x12345678.remainder(0x22) as int));
expect(Int32(0x12345678).remainder(Int32(-0x22)),
@@ -127,7 +127,7 @@
expect(() => Int32(17).remainder(null), throwsArgumentError);
});
- test("abs", () {
+ test('abs', () {
// NOTE: Int32.MIN_VALUE.abs() is undefined
expect((Int32.MIN_VALUE + 1).abs(), Int32.MAX_VALUE);
expect(Int32(-1).abs(), Int32(1));
@@ -136,8 +136,8 @@
expect(Int32.MAX_VALUE.abs(), Int32.MAX_VALUE);
});
- test("clamp", () {
- Int32 val = Int32(17);
+ test('clamp', () {
+ var val = Int32(17);
expect(val.clamp(20, 30), Int32(20));
expect(val.clamp(10, 20), Int32(17));
expect(val.clamp(10, 15), Int32(15));
@@ -160,14 +160,14 @@
});
});
- group("leading/trailing zeros", () {
- test("numberOfLeadingZeros", () {
+ group('leading/trailing zeros', () {
+ test('numberOfLeadingZeros', () {
expect(Int32(0).numberOfLeadingZeros(), 32);
expect(Int32(1).numberOfLeadingZeros(), 31);
expect(Int32(0xffff).numberOfLeadingZeros(), 16);
expect(Int32(-1).numberOfLeadingZeros(), 0);
});
- test("numberOfTrailingZeros", () {
+ test('numberOfTrailingZeros', () {
expect(Int32(0).numberOfTrailingZeros(), 32);
expect(Int32(0x80000000).numberOfTrailingZeros(), 31);
expect(Int32(1).numberOfTrailingZeros(), 0);
@@ -175,8 +175,8 @@
});
});
- group("comparison operators", () {
- test("compareTo", () {
+ group('comparison operators', () {
+ test('compareTo', () {
expect(Int32(0).compareTo(-1), 1);
expect(Int32(0).compareTo(0), 0);
expect(Int32(0).compareTo(1), -1);
@@ -188,7 +188,7 @@
expect(Int32(0).compareTo(Int64(1)), -1);
});
- test("<", () {
+ test('<', () {
expect(Int32(17) < Int32(18), true);
expect(Int32(17) < Int32(17), false);
expect(Int32(17) < Int32(16), false);
@@ -200,7 +200,7 @@
expect(() => Int32(17) < null, throwsArgumentError);
});
- test("<=", () {
+ test('<=', () {
expect(Int32(17) <= Int32(18), true);
expect(Int32(17) <= Int32(17), true);
expect(Int32(17) <= Int32(16), false);
@@ -212,7 +212,7 @@
expect(() => Int32(17) <= null, throwsArgumentError);
});
- test("==", () {
+ test('==', () {
expect(Int32(17), isNot(equals(Int32(18))));
expect(Int32(17), equals(Int32(17)));
expect(Int32(17), isNot(equals(Int32(16))));
@@ -227,7 +227,7 @@
expect(Int32(17), isNot(equals(null)));
});
- test(">=", () {
+ test('>=', () {
expect(Int32(17) >= Int32(18), false);
expect(Int32(17) >= Int32(17), true);
expect(Int32(17) >= Int32(16), true);
@@ -239,7 +239,7 @@
expect(() => Int32(17) >= null, throwsArgumentError);
});
- test(">", () {
+ test('>', () {
expect(Int32(17) > Int32(18), false);
expect(Int32(17) > Int32(17), false);
expect(Int32(17) > Int32(16), true);
@@ -252,8 +252,8 @@
});
});
- group("bitwise operators", () {
- test("&", () {
+ group('bitwise operators', () {
+ test('&', () {
expect(Int32(0x12345678) & Int32(0x22222222),
Int32(0x12345678 & 0x22222222));
expect(Int32(0x12345678) & Int64(0x22222222),
@@ -261,7 +261,7 @@
expect(() => Int32(17) & null, throwsArgumentError);
});
- test("|", () {
+ test('|', () {
expect(Int32(0x12345678) | Int32(0x22222222),
Int32(0x12345678 | 0x22222222));
expect(Int32(0x12345678) | Int64(0x22222222),
@@ -269,7 +269,7 @@
expect(() => Int32(17) | null, throwsArgumentError);
});
- test("^", () {
+ test('^', () {
expect(Int32(0x12345678) ^ Int32(0x22222222),
Int32(0x12345678 ^ 0x22222222));
expect(Int32(0x12345678) ^ Int64(0x22222222),
@@ -277,14 +277,14 @@
expect(() => Int32(17) ^ null, throwsArgumentError);
});
- test("~", () {
+ test('~', () {
expect(~(Int32(0x12345678)), Int32(~0x12345678));
expect(-(Int32(0x12345678)), Int64(-0x12345678));
});
});
- group("bitshift operators", () {
- test("<<", () {
+ group('bitshift operators', () {
+ test('<<', () {
expect(Int32(0x12345678) << 7, Int32(0x12345678 << 7));
expect(Int32(0x12345678) << 32, Int32.ZERO);
expect(Int32(0x12345678) << 33, Int32.ZERO);
@@ -292,7 +292,7 @@
expect(() => Int32(17) << null, throwsNoSuchMethodError);
});
- test(">>", () {
+ test('>>', () {
expect(Int32(0x12345678) >> 7, Int32(0x12345678 >> 7));
expect(Int32(0x12345678) >> 32, Int32.ZERO);
expect(Int32(0x12345678) >> 33, Int32.ZERO);
@@ -302,7 +302,7 @@
expect(() => Int32(17) >> null, throwsNoSuchMethodError);
});
- test("shiftRightUnsigned", () {
+ test('shiftRightUnsigned', () {
expect(Int32(0x12345678).shiftRightUnsigned(7), Int32(0x12345678 >> 7));
expect(Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO);
expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO);
@@ -314,8 +314,8 @@
});
});
- group("conversions", () {
- test("toSigned", () {
+ group('conversions', () {
+ test('toSigned', () {
expect(Int32.ONE.toSigned(2), Int32.ONE);
expect(Int32.ONE.toSigned(1), -Int32.ONE);
expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE);
@@ -325,7 +325,7 @@
expect(() => Int32.ONE.toSigned(0), throwsRangeError);
expect(() => Int32.ONE.toSigned(33), throwsRangeError);
});
- test("toUnsigned", () {
+ test('toUnsigned', () {
expect(Int32.ONE.toUnsigned(1), Int32.ONE);
expect(Int32.ONE.toUnsigned(0), Int32.ZERO);
expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE);
@@ -335,23 +335,23 @@
expect(() => Int32.ONE.toUnsigned(-1), throwsRangeError);
expect(() => Int32.ONE.toUnsigned(33), throwsRangeError);
});
- test("toDouble", () {
+ test('toDouble', () {
expect(Int32(17).toDouble(), same(17.0));
expect(Int32(-17).toDouble(), same(-17.0));
});
- test("toInt", () {
+ test('toInt', () {
expect(Int32(17).toInt(), 17);
expect(Int32(-17).toInt(), -17);
});
- test("toInt32", () {
+ test('toInt32', () {
expect(Int32(17).toInt32(), Int32(17));
expect(Int32(-17).toInt32(), Int32(-17));
});
- test("toInt64", () {
+ test('toInt64', () {
expect(Int32(17).toInt64(), Int64(17));
expect(Int32(-17).toInt64(), Int64(-17));
});
- test("toBytes", () {
+ test('toBytes', () {
expect(Int32(0).toBytes(), [0, 0, 0, 0]);
expect(Int32(0x01020304).toBytes(), [4, 3, 2, 1]);
expect(Int32(0x04030201).toBytes(), [1, 2, 3, 4]);
@@ -359,9 +359,9 @@
});
});
- group("parse", () {
- test("base 10", () {
- checkInt(int x) {
+ group('parse', () {
+ test('base 10', () {
+ void checkInt(int x) {
expect(Int32.parseRadix('$x', 10), Int32(x));
}
@@ -377,8 +377,8 @@
expect(() => Int32.parseRadix('plugh', 10), throwsFormatException);
});
- test("parseRadix", () {
- check(String s, int r, String x) {
+ test('parseRadix', () {
+ void check(String s, int r, String x) {
expect(Int32.parseRadix(s, r).toString(), x);
}
@@ -386,50 +386,50 @@
check('95', 12, '113');
});
- test("parseInt", () {
+ test('parseInt', () {
expect(Int32.parseInt('0'), Int32(0));
expect(Int32.parseInt('1000'), Int32(1000));
expect(Int32.parseInt('4294967296'), Int32(4294967296));
});
- test("parseHex", () {
+ test('parseHex', () {
expect(Int32.parseHex('deadbeef'), Int32(0xdeadbeef));
expect(Int32.parseHex('cafebabe'), Int32(0xcafebabe));
expect(Int32.parseHex('8badf00d'), Int32(0x8badf00d));
});
});
- group("string representation", () {
- test("toString", () {
- expect(Int32(0).toString(), "0");
- expect(Int32(1).toString(), "1");
- expect(Int32(-1).toString(), "-1");
- expect(Int32(1000).toString(), "1000");
- expect(Int32(-1000).toString(), "-1000");
- expect(Int32(123456789).toString(), "123456789");
- expect(Int32(2147483647).toString(), "2147483647");
- expect(Int32(2147483648).toString(), "-2147483648");
- expect(Int32(2147483649).toString(), "-2147483647");
- expect(Int32(2147483650).toString(), "-2147483646");
- expect(Int32(-2147483648).toString(), "-2147483648");
- expect(Int32(-2147483649).toString(), "2147483647");
- expect(Int32(-2147483650).toString(), "2147483646");
+ group('string representation', () {
+ test('toString', () {
+ expect(Int32(0).toString(), '0');
+ expect(Int32(1).toString(), '1');
+ expect(Int32(-1).toString(), '-1');
+ expect(Int32(1000).toString(), '1000');
+ expect(Int32(-1000).toString(), '-1000');
+ expect(Int32(123456789).toString(), '123456789');
+ expect(Int32(2147483647).toString(), '2147483647');
+ expect(Int32(2147483648).toString(), '-2147483648');
+ expect(Int32(2147483649).toString(), '-2147483647');
+ expect(Int32(2147483650).toString(), '-2147483646');
+ expect(Int32(-2147483648).toString(), '-2147483648');
+ expect(Int32(-2147483649).toString(), '2147483647');
+ expect(Int32(-2147483650).toString(), '2147483646');
});
});
- group("toHexString", () {
- test("returns hexadecimal string representation", () {
- expect(Int32(-1).toHexString(), "-1");
- expect((Int32(-1) >> 8).toHexString(), "-1");
- expect((Int32(-1) << 8).toHexString(), "-100");
- expect(Int32(123456789).toHexString(), "75bcd15");
- expect(Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff");
+ group('toHexString', () {
+ test('returns hexadecimal string representation', () {
+ expect(Int32(-1).toHexString(), '-1');
+ expect((Int32(-1) >> 8).toHexString(), '-1');
+ expect((Int32(-1) << 8).toHexString(), '-100');
+ expect(Int32(123456789).toHexString(), '75bcd15');
+ expect(Int32(-1).shiftRightUnsigned(8).toHexString(), 'ffffff');
});
});
- group("toRadixString", () {
- test("returns base n string representation", () {
- expect(Int32(123456789).toRadixString(5), "223101104124");
+ group('toRadixString', () {
+ test('returns base n string representation', () {
+ expect(Int32(123456789).toRadixString(5), '223101104124');
});
});
}
diff --git a/test/int64_test.dart b/test/int64_test.dart
index 1acc3a4..7994a8d 100644
--- a/test/int64_test.dart
+++ b/test/int64_test.dart
@@ -2,15 +2,20 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// We permit local variable types in this test because they statically 'assert'
+// that the operations have an expected type.
+//
+// ignore_for_file: omit_local_variable_types
+
library int64test;
import 'package:fixnum/fixnum.dart';
import 'package:test/test.dart';
void main() {
- group("fromBytes", () {
- test("fromBytes", () {
- checkBytes(List<int> bytes, int h, int l) {
+ group('fromBytes', () {
+ test('fromBytes', () {
+ void checkBytes(List<int> bytes, int h, int l) {
expect(Int64.fromBytes(bytes), Int64.fromInts(h, l));
}
@@ -22,8 +27,8 @@
checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff,
0xffffffff);
});
- test("fromBytesBigEndian", () {
- checkBytes(List<int> bytes, int h, int l) {
+ test('fromBytesBigEndian', () {
+ void checkBytes(List<int> bytes, int h, int l) {
expect(Int64.fromBytesBigEndian(bytes), Int64.fromInts(h, l));
}
@@ -37,48 +42,48 @@
});
});
- argumentErrorTest(name, op, [receiver = Int64.ONE]) {
- throwsArgumentErrorMentioning(String substring) =>
+ void argumentErrorTest(name, op, [receiver = Int64.ONE]) {
+ Matcher throwsArgumentErrorMentioning(String substring) =>
throwsA((e) => e is ArgumentError && '$e'.contains(substring));
expect(() => op(receiver, null), throwsArgumentErrorMentioning('null'));
expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"'));
}
- group("is-tests", () {
- test("isEven", () {
+ group('is-tests', () {
+ test('isEven', () {
expect((-Int64.ONE).isEven, false);
expect(Int64.ZERO.isEven, true);
expect(Int64.ONE.isEven, false);
expect(Int64.TWO.isEven, true);
});
- test("isMaxValue", () {
+ test('isMaxValue', () {
expect(Int64.MIN_VALUE.isMaxValue, false);
expect(Int64.ZERO.isMaxValue, false);
expect(Int64.MAX_VALUE.isMaxValue, true);
});
- test("isMinValue", () {
+ test('isMinValue', () {
expect(Int64.MIN_VALUE.isMinValue, true);
expect(Int64.ZERO.isMinValue, false);
expect(Int64.MAX_VALUE.isMinValue, false);
});
- test("isNegative", () {
+ test('isNegative', () {
expect(Int64.MIN_VALUE.isNegative, true);
expect(Int64.ZERO.isNegative, false);
expect(Int64.ONE.isNegative, false);
});
- test("isOdd", () {
+ test('isOdd', () {
expect((-Int64.ONE).isOdd, true);
expect(Int64.ZERO.isOdd, false);
expect(Int64.ONE.isOdd, true);
expect(Int64.TWO.isOdd, false);
});
- test("isZero", () {
+ test('isZero', () {
expect(Int64.MIN_VALUE.isZero, false);
expect(Int64.ZERO.isZero, true);
expect(Int64.MAX_VALUE.isZero, false);
});
- test("bitLength", () {
+ test('bitLength', () {
expect(Int64(-2).bitLength, 1);
expect((-Int64.ONE).bitLength, 0);
expect(Int64.ZERO.bitLength, 0);
@@ -92,7 +97,7 @@
});
});
- group("arithmetic operators", () {
+ group('arithmetic operators', () {
Int64 n1 = Int64(1234);
Int64 n2 = Int64(9876);
Int64 n3 = Int64(-1234);
@@ -100,30 +105,30 @@
Int64 n5 = Int64.fromInts(0x12345678, 0xabcdabcd);
Int64 n6 = Int64.fromInts(0x77773333, 0x22224444);
- test("+", () {
+ test('+', () {
expect(n1 + n2, Int64(11110));
expect(n3 + n2, Int64(8642));
expect(n3 + n4, Int64(-11110));
expect(n5 + n6, Int64.fromInts(0x89ab89ab, 0xcdeff011));
expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE);
- argumentErrorTest("+", (a, b) => a + b);
+ argumentErrorTest('+', (a, b) => a + b);
});
- test("-", () {
+ test('-', () {
expect(n1 - n2, Int64(-8642));
expect(n3 - n2, Int64(-11110));
expect(n3 - n4, Int64(8642));
expect(n5 - n6, Int64.fromInts(0x9abd2345, 0x89ab6789));
expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE);
- argumentErrorTest("-", (a, b) => a - b);
+ argumentErrorTest('-', (a, b) => a - b);
});
- test("unary -", () {
+ test('unary -', () {
expect(-n1, Int64(-1234));
expect(-Int64.ZERO, Int64.ZERO);
});
- test("*", () {
+ test('*', () {
expect(Int64(1111) * Int64(3), Int64(3333));
expect(Int64(1111) * Int64(-3), Int64(-3333));
expect(Int64(-1111) * Int64(3), Int64(-3333));
@@ -156,10 +161,10 @@
expect(Int64.MIN_VALUE * Int64(2), Int64.ZERO);
expect(Int64.MIN_VALUE * Int64(1), Int64.MIN_VALUE);
expect(Int64.MIN_VALUE * Int64(-1), Int64.MIN_VALUE);
- argumentErrorTest("*", (a, b) => a * b);
+ argumentErrorTest('*', (a, b) => a * b);
});
- test("~/", () {
+ test('~/', () {
Int64 deadBeef = Int64.fromInts(0xDEADBEEF, 0xDEADBEEF);
Int64 ten = Int64(10);
@@ -233,10 +238,10 @@
expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE);
expect(() => Int64(17) ~/ Int64.ZERO,
throwsA(const TypeMatcher<IntegerDivisionByZeroException>()));
- argumentErrorTest("~/", (a, b) => a ~/ b);
+ argumentErrorTest('~/', (a, b) => a ~/ b);
});
- test("%", () {
+ test('%', () {
// Define % as Euclidean mod, with positive result for all arguments
expect(Int64.ZERO % Int64(1000), Int64.ZERO);
expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO);
@@ -273,10 +278,10 @@
Int64(-0x12345678.remainder(0x22) as int));
expect(Int32(0x12345678).remainder(Int64(0x22)),
Int64(0x12345678.remainder(0x22) as int));
- argumentErrorTest("%", (a, b) => a % b);
+ argumentErrorTest('%', (a, b) => a % b);
});
- test("clamp", () {
+ test('clamp', () {
Int64 val = Int64(17);
expect(val.clamp(20, 30), Int64(20));
expect(val.clamp(10, 20), Int64(17));
@@ -297,9 +302,9 @@
});
});
- group("leading/trailing zeros", () {
- test("numberOfLeadingZeros", () {
- checkZeros(Int64 value, int zeros) {
+ group('leading/trailing zeros', () {
+ test('numberOfLeadingZeros', () {
+ void checkZeros(Int64 value, int zeros) {
expect(value.numberOfLeadingZeros(), zeros);
}
@@ -313,8 +318,8 @@
checkZeros(Int64(-1), 0);
});
- test("numberOfTrailingZeros", () {
- checkZeros(Int64 value, int zeros) {
+ test('numberOfTrailingZeros', () {
+ void checkZeros(Int64 value, int zeros) {
expect(value.numberOfTrailingZeros(), zeros);
}
@@ -330,12 +335,12 @@
});
});
- group("comparison operators", () {
+ group('comparison operators', () {
Int64 largeNeg = Int64.fromInts(0x82341234, 0x0);
Int64 largePos = Int64.fromInts(0x12341234, 0x0);
Int64 largePosPlusOne = largePos + Int64(1);
- test("<", () {
+ test('<', () {
expect(Int64(10) < Int64(11), true);
expect(Int64(10) < Int64(10), false);
expect(Int64(10) < Int64(9), false);
@@ -350,10 +355,10 @@
expect(largePosPlusOne < largePos, false);
expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false);
- argumentErrorTest("<", (a, b) => a < b);
+ argumentErrorTest('<', (a, b) => a < b);
});
- test("<=", () {
+ test('<=', () {
expect(Int64(10) <= Int64(11), true);
expect(Int64(10) <= Int64(10), true);
expect(Int64(10) <= Int64(9), false);
@@ -369,10 +374,10 @@
expect(largePosPlusOne <= largePos, false);
expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false);
- argumentErrorTest("<=", (a, b) => a <= b);
+ argumentErrorTest('<=', (a, b) => a <= b);
});
- test("==", () {
+ test('==', () {
expect(Int64(0), equals(Int64(0)));
expect(Int64(0), isNot(equals(Int64(1))));
expect(Int64(0), equals(Int32(0)));
@@ -400,7 +405,7 @@
expect(Int64(17), isNot(equals(null)));
});
- test(">=", () {
+ test('>=', () {
expect(Int64(10) >= Int64(11), false);
expect(Int64(10) >= Int64(10), true);
expect(Int64(10) >= Int64(9), true);
@@ -416,10 +421,10 @@
expect(largePosPlusOne >= largePos, true);
expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true);
- argumentErrorTest(">=", (a, b) => a >= b);
+ argumentErrorTest('>=', (a, b) => a >= b);
});
- test(">", () {
+ test('>', () {
expect(Int64(10) > Int64(11), false);
expect(Int64(10) > Int64(10), false);
expect(Int64(10) > Int64(9), true);
@@ -437,42 +442,42 @@
expect(Int64.ZERO > Int64.MIN_VALUE, true);
expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true);
- argumentErrorTest(">", (a, b) => a > b);
+ argumentErrorTest('>', (a, b) => a > b);
});
});
- group("bitwise operators", () {
+ group('bitwise operators', () {
Int64 n1 = Int64(1234);
Int64 n2 = Int64(9876);
Int64 n3 = Int64(-1234);
Int64 n4 = Int64(0x1234) << 32;
Int64 n5 = Int64(0x9876) << 32;
- test("&", () {
+ test('&', () {
expect(n1 & n2, Int64(1168));
expect(n3 & n2, Int64(8708));
expect(n4 & n5, Int64(0x1034) << 32);
expect(() => n1 & null, throwsArgumentError);
- argumentErrorTest("&", (a, b) => a & b);
+ argumentErrorTest('&', (a, b) => a & b);
});
- test("|", () {
+ test('|', () {
expect(n1 | n2, Int64(9942));
expect(n3 | n2, Int64(-66));
expect(n4 | n5, Int64(0x9a76) << 32);
expect(() => n1 | null, throwsArgumentError);
- argumentErrorTest("|", (a, b) => a | b);
+ argumentErrorTest('|', (a, b) => a | b);
});
- test("^", () {
+ test('^', () {
expect(n1 ^ n2, Int64(8774));
expect(n3 ^ n2, Int64(-8774));
expect(n4 ^ n5, Int64(0x8a42) << 32);
expect(() => n1 ^ null, throwsArgumentError);
- argumentErrorTest("^", (a, b) => a ^ b);
+ argumentErrorTest('^', (a, b) => a ^ b);
});
- test("~", () {
+ test('~', () {
expect(-Int64(1), Int64(-1));
expect(-Int64(-1), Int64(1));
expect(-Int64.MIN_VALUE, Int64.MIN_VALUE);
@@ -485,8 +490,8 @@
});
});
- group("bitshift operators", () {
- test("<<", () {
+ group('bitshift operators', () {
+ test('<<', () {
expect(Int64.fromInts(0x12341234, 0x45674567) << 10,
Int64.fromInts(0xd048d115, 0x9d159c00));
expect(Int64.fromInts(0x92341234, 0x45674567) << 10,
@@ -499,8 +504,8 @@
expect(() => Int64(17) << null, throwsNoSuchMethodError);
});
- test(">>", () {
- expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624");
+ test('>>', () {
+ expect((Int64.MIN_VALUE >> 13).toString(), '-1125899906842624');
expect(Int64.fromInts(0x12341234, 0x45674567) >> 10,
Int64.fromInts(0x48d04, 0x8d1159d1));
expect(Int64.fromInts(0x92341234, 0x45674567) >> 10,
@@ -551,7 +556,7 @@
expect(() => Int64(17) >> null, throwsNoSuchMethodError);
});
- test("shiftRightUnsigned", () {
+ test('shiftRightUnsigned', () {
expect(Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10),
Int64.fromInts(0x48d04, 0x8d1159d1));
expect(Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10),
@@ -598,7 +603,7 @@
expect(() => Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError);
});
- test("overflow", () {
+ test('overflow', () {
expect((Int64(1) << 63) >> 1, -Int64.fromInts(0x40000000, 0x00000000));
expect((Int64(-1) << 32) << 32, Int64(0));
expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE);
@@ -610,8 +615,8 @@
});
});
- group("conversions", () {
- test("toSigned", () {
+ group('conversions', () {
+ test('toSigned', () {
expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44);
expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44));
expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22);
@@ -625,7 +630,7 @@
expect(() => Int64.ONE.toSigned(0), throwsRangeError);
expect(() => Int64.ONE.toSigned(65), throwsRangeError);
});
- test("toUnsigned", () {
+ test('toUnsigned', () {
expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44);
expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO);
expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22);
@@ -639,7 +644,7 @@
expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError);
expect(() => Int64.ONE.toUnsigned(65), throwsRangeError);
});
- test("toDouble", () {
+ test('toDouble', () {
expect(Int64(0).toDouble(), same(0.0));
expect(Int64(100).toDouble(), same(100.0));
expect(Int64(-100).toDouble(), same(-100.0));
@@ -651,27 +656,27 @@
expect(Int64(4503599627370496).toDouble(), same(4503599627370496.0));
expect(Int64(-4503599627370495).toDouble(), same(-4503599627370495.0));
expect(Int64(-4503599627370496).toDouble(), same(-4503599627370496.0));
- expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1),
- "-10000000000000000.0");
- expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1),
- "-10000000000000000.0");
- expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1),
- "-10000000000000002.0");
- expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1),
- "-10000000000000004.0");
- expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1),
- "-10000000000000004.0");
- expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1),
- "-10000000000000004.0");
- expect(Int64.parseInt("-10000000000000006").toDouble().toStringAsFixed(1),
- "-10000000000000006.0");
- expect(Int64.parseInt("-10000000000000007").toDouble().toStringAsFixed(1),
- "-10000000000000008.0");
- expect(Int64.parseInt("-10000000000000008").toDouble().toStringAsFixed(1),
- "-10000000000000008.0");
+ expect(Int64.parseInt('-10000000000000000').toDouble().toStringAsFixed(1),
+ '-10000000000000000.0');
+ expect(Int64.parseInt('-10000000000000001').toDouble().toStringAsFixed(1),
+ '-10000000000000000.0');
+ expect(Int64.parseInt('-10000000000000002').toDouble().toStringAsFixed(1),
+ '-10000000000000002.0');
+ expect(Int64.parseInt('-10000000000000003').toDouble().toStringAsFixed(1),
+ '-10000000000000004.0');
+ expect(Int64.parseInt('-10000000000000004').toDouble().toStringAsFixed(1),
+ '-10000000000000004.0');
+ expect(Int64.parseInt('-10000000000000005').toDouble().toStringAsFixed(1),
+ '-10000000000000004.0');
+ expect(Int64.parseInt('-10000000000000006').toDouble().toStringAsFixed(1),
+ '-10000000000000006.0');
+ expect(Int64.parseInt('-10000000000000007').toDouble().toStringAsFixed(1),
+ '-10000000000000008.0');
+ expect(Int64.parseInt('-10000000000000008').toDouble().toStringAsFixed(1),
+ '-10000000000000008.0');
});
- test("toInt", () {
+ test('toInt', () {
expect(Int64(0).toInt(), 0);
expect(Int64(100).toInt(), 100);
expect(Int64(-100).toInt(), -100);
@@ -685,7 +690,7 @@
expect(Int64(-4503599627370496).toInt(), -4503599627370496);
});
- test("toInt32", () {
+ test('toInt32', () {
expect(Int64(0).toInt32(), Int32(0));
expect(Int64(1).toInt32(), Int32(1));
expect(Int64(-1).toInt32(), Int32(-1));
@@ -699,7 +704,7 @@
expect(Int64(-2147483651).toInt32(), Int32(2147483645));
});
- test("toBytes", () {
+ test('toBytes', () {
expect(Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]);
expect(Int64.fromInts(0x08070605, 0x04030201).toBytes(),
[1, 2, 3, 4, 5, 6, 7, 8]);
@@ -710,7 +715,7 @@
});
});
- test("JavaScript 53-bit integer boundary", () {
+ test('JavaScript 53-bit integer boundary', () {
Int64 _factorial(Int64 n) {
if (n.isZero) {
return Int64(1);
@@ -724,13 +729,13 @@
expect(fact18 ~/ fact17, Int64(18));
});
- test("min, max values", () {
+ test('min, max values', () {
expect(Int64(1) << 63, Int64.MIN_VALUE);
expect(-(Int64.MIN_VALUE + Int64(1)), Int64.MAX_VALUE);
});
- test("negation", () {
- check(int n) {
+ test('negation', () {
+ void check(int n) {
// Sign change should commute with conversion.
expect(-Int64(-n), Int64(n));
expect(Int64(-n), -Int64(n));
@@ -741,9 +746,9 @@
check(9223372000000000000); // near Int64.MAX_VALUE, has exact double value
});
- group("parse", () {
- test("parseRadix10", () {
- checkInt(int x) {
+ group('parse', () {
+ test('parseRadix10', () {
+ void checkInt(int x) {
expect(Int64.parseRadix('$x', 10), Int64(x));
}
@@ -767,8 +772,8 @@
expect(() => Int64.parseRadix('-', 10), throwsFormatException);
});
- test("parseHex", () {
- checkHex(String hexStr, int h, int l) {
+ test('parseHex', () {
+ void checkHex(String hexStr, int h, int l) {
expect(Int64.parseHex(hexStr), Int64.fromInts(h, l));
}
@@ -789,18 +794,18 @@
expect(() => Int64.parseHex('-'), throwsFormatException);
});
- test("parseRadix", () {
- check(String s, int r, String x) {
+ test('parseRadix', () {
+ void check(String s, int r, String x) {
expect(Int64.parseRadix(s, r).toString(), x);
}
check('ghoul', 36, '27699213');
check('ghoul', 35, '24769346');
// Min and max value.
- check("-9223372036854775808", 10, "-9223372036854775808");
- check("9223372036854775807", 10, "9223372036854775807");
+ check('-9223372036854775808', 10, '-9223372036854775808');
+ check('9223372036854775807', 10, '9223372036854775807');
// Overflow during parsing.
- check("9223372036854775808", 10, "-9223372036854775808");
+ check('9223372036854775808', 10, '-9223372036854775808');
expect(() => Int64.parseRadix('0', 1), throwsRangeError);
expect(() => Int64.parseRadix('0', 37), throwsRangeError);
@@ -808,85 +813,85 @@
expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException);
});
- test("parseRadixN", () {
- check(String s, int r) {
+ test('parseRadixN', () {
+ void check(String s, int r) {
expect(Int64.parseRadix(s, r).toRadixString(r), s);
}
- check("2ppp111222333", 33); // This value & radix requires three chunks.
+ check('2ppp111222333', 33); // This value & radix requires three chunks.
});
});
- group("string representation", () {
- test("toString", () {
- expect(Int64(0).toString(), "0");
- expect(Int64(1).toString(), "1");
- expect(Int64(-1).toString(), "-1");
- expect(Int64(-10).toString(), "-10");
- expect(Int64.MIN_VALUE.toString(), "-9223372036854775808");
- expect(Int64.MAX_VALUE.toString(), "9223372036854775807");
+ group('string representation', () {
+ test('toString', () {
+ expect(Int64(0).toString(), '0');
+ expect(Int64(1).toString(), '1');
+ expect(Int64(-1).toString(), '-1');
+ expect(Int64(-10).toString(), '-10');
+ expect(Int64.MIN_VALUE.toString(), '-9223372036854775808');
+ expect(Int64.MAX_VALUE.toString(), '9223372036854775807');
int top = 922337201;
int bottom = 967490662;
Int64 fullnum = (Int64(1000000000) * Int64(top)) + Int64(bottom);
- expect(fullnum.toString(), "922337201967490662");
- expect((-fullnum).toString(), "-922337201967490662");
- expect(Int64(123456789).toString(), "123456789");
+ expect(fullnum.toString(), '922337201967490662');
+ expect((-fullnum).toString(), '-922337201967490662');
+ expect(Int64(123456789).toString(), '123456789');
});
- test("toHexString", () {
+ test('toHexString', () {
Int64 deadbeef12341234 = Int64.fromInts(0xDEADBEEF, 0x12341234);
- expect(Int64.ZERO.toHexString(), "0");
- expect(deadbeef12341234.toHexString(), "DEADBEEF12341234");
+ expect(Int64.ZERO.toHexString(), '0');
+ expect(deadbeef12341234.toHexString(), 'DEADBEEF12341234');
expect(Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(),
- "17678A7DEF01234");
- expect(Int64(123456789).toHexString(), "75BCD15");
+ '17678A7DEF01234');
+ expect(Int64(123456789).toHexString(), '75BCD15');
});
- test("toRadixString", () {
- expect(Int64(123456789).toRadixString(5), "223101104124");
+ test('toRadixString', () {
+ expect(Int64(123456789).toRadixString(5), '223101104124');
expect(Int64.MIN_VALUE.toRadixString(2),
- "-1000000000000000000000000000000000000000000000000000000000000000");
+ '-1000000000000000000000000000000000000000000000000000000000000000');
expect(Int64.MIN_VALUE.toRadixString(3),
- "-2021110011022210012102010021220101220222");
+ '-2021110011022210012102010021220101220222');
expect(Int64.MIN_VALUE.toRadixString(4),
- "-20000000000000000000000000000000");
- expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213");
- expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212");
- expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301");
- expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000");
- expect(Int64.MIN_VALUE.toRadixString(9), "-67404283172107811828");
- expect(Int64.MIN_VALUE.toRadixString(10), "-9223372036854775808");
- expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698");
- expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368");
- expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38");
- expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8");
- expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808");
- expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000");
+ '-20000000000000000000000000000000');
+ expect(Int64.MIN_VALUE.toRadixString(5), '-1104332401304422434310311213');
+ expect(Int64.MIN_VALUE.toRadixString(6), '-1540241003031030222122212');
+ expect(Int64.MIN_VALUE.toRadixString(7), '-22341010611245052052301');
+ expect(Int64.MIN_VALUE.toRadixString(8), '-1000000000000000000000');
+ expect(Int64.MIN_VALUE.toRadixString(9), '-67404283172107811828');
+ expect(Int64.MIN_VALUE.toRadixString(10), '-9223372036854775808');
+ expect(Int64.MIN_VALUE.toRadixString(11), '-1728002635214590698');
+ expect(Int64.MIN_VALUE.toRadixString(12), '-41a792678515120368');
+ expect(Int64.MIN_VALUE.toRadixString(13), '-10b269549075433c38');
+ expect(Int64.MIN_VALUE.toRadixString(14), '-4340724c6c71dc7a8');
+ expect(Int64.MIN_VALUE.toRadixString(15), '-160e2ad3246366808');
+ expect(Int64.MIN_VALUE.toRadixString(16), '-8000000000000000');
expect(Int64.MAX_VALUE.toRadixString(2),
- "111111111111111111111111111111111111111111111111111111111111111");
+ '111111111111111111111111111111111111111111111111111111111111111');
expect(Int64.MAX_VALUE.toRadixString(3),
- "2021110011022210012102010021220101220221");
+ '2021110011022210012102010021220101220221');
expect(
- Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333");
- expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212");
- expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211");
- expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300");
- expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777");
- expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827");
- expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807");
- expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697");
- expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367");
- expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37");
- expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7");
- expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807");
- expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff");
+ Int64.MAX_VALUE.toRadixString(4), '13333333333333333333333333333333');
+ expect(Int64.MAX_VALUE.toRadixString(5), '1104332401304422434310311212');
+ expect(Int64.MAX_VALUE.toRadixString(6), '1540241003031030222122211');
+ expect(Int64.MAX_VALUE.toRadixString(7), '22341010611245052052300');
+ expect(Int64.MAX_VALUE.toRadixString(8), '777777777777777777777');
+ expect(Int64.MAX_VALUE.toRadixString(9), '67404283172107811827');
+ expect(Int64.MAX_VALUE.toRadixString(10), '9223372036854775807');
+ expect(Int64.MAX_VALUE.toRadixString(11), '1728002635214590697');
+ expect(Int64.MAX_VALUE.toRadixString(12), '41a792678515120367');
+ expect(Int64.MAX_VALUE.toRadixString(13), '10b269549075433c37');
+ expect(Int64.MAX_VALUE.toRadixString(14), '4340724c6c71dc7a7');
+ expect(Int64.MAX_VALUE.toRadixString(15), '160e2ad3246366807');
+ expect(Int64.MAX_VALUE.toRadixString(16), '7fffffffffffffff');
expect(() => Int64(42).toRadixString(-1), throwsArgumentError);
expect(() => Int64(42).toRadixString(0), throwsArgumentError);
expect(() => Int64(42).toRadixString(37), throwsArgumentError);
});
- test("toStringUnsigned", () {
+ test('toStringUnsigned', () {
List<Int64> values = [];
for (int high = 0; high < 16; high++) {
for (int low = -2; low <= 2; low++) {
diff --git a/test/int_64_vm_test.dart b/test/int_64_vm_test.dart
index e5e1303..2ab161e 100644
--- a/test/int_64_vm_test.dart
+++ b/test/int_64_vm_test.dart
@@ -8,31 +8,31 @@
import 'package:test/test.dart';
void main() {
- group("conversions", () {
- test("toInt", () {
- expect(Int64.parseInt("-10000000000000000").toInt(),
+ group('conversions', () {
+ test('toInt', () {
+ expect(Int64.parseInt('-10000000000000000').toInt(),
same(-10000000000000000));
- expect(Int64.parseInt("-10000000000000001").toInt(),
+ expect(Int64.parseInt('-10000000000000001').toInt(),
same(-10000000000000001));
- expect(Int64.parseInt("-10000000000000002").toInt(),
+ expect(Int64.parseInt('-10000000000000002').toInt(),
same(-10000000000000002));
- expect(Int64.parseInt("-10000000000000003").toInt(),
+ expect(Int64.parseInt('-10000000000000003').toInt(),
same(-10000000000000003));
- expect(Int64.parseInt("-10000000000000004").toInt(),
+ expect(Int64.parseInt('-10000000000000004').toInt(),
same(-10000000000000004));
- expect(Int64.parseInt("-10000000000000005").toInt(),
+ expect(Int64.parseInt('-10000000000000005').toInt(),
same(-10000000000000005));
- expect(Int64.parseInt("-10000000000000006").toInt(),
+ expect(Int64.parseInt('-10000000000000006').toInt(),
same(-10000000000000006));
- expect(Int64.parseInt("-10000000000000007").toInt(),
+ expect(Int64.parseInt('-10000000000000007').toInt(),
same(-10000000000000007));
- expect(Int64.parseInt("-10000000000000008").toInt(),
+ expect(Int64.parseInt('-10000000000000008').toInt(),
same(-10000000000000008));
});
});
- test("", () {
- check(int n) {
+ test('', () {
+ void check(int n) {
// Sign change should commute with conversion.
expect(-Int64(-n), Int64(n));
expect(Int64(-n), -Int64(n));