Enable and fix a number of lints (#45)
Almost entirely `dartfmt --fix -w .`
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..8ef67de
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,58 @@
+include: package:pedantic/analysis_options.yaml
+linter:
+ rules:
+ #- annotate_overrides
+ - avoid_function_literals_in_foreach_calls
+ - avoid_init_to_null
+ - avoid_null_checks_in_equality_operators
+ - avoid_relative_lib_imports
+ - avoid_returning_null
+ - avoid_unused_constructor_parameters
+ - await_only_futures
+ - camel_case_types
+ - cancel_subscriptions
+ - comment_references
+ #- constant_identifier_names
+ - control_flow_in_finally
+ - directives_ordering
+ - empty_catches
+ - empty_constructor_bodies
+ - empty_statements
+ - hash_and_equals
+ - implementation_imports
+ - invariant_booleans
+ - iterable_contains_unrelated_type
+ - library_names
+ - library_prefixes
+ - 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
+ - package_names
+ - package_prefixed_library_names
+ - prefer_adjacent_string_concatenation
+ - prefer_collection_literals
+ - prefer_conditional_assignment
+ - prefer_const_constructors
+ - prefer_final_fields
+ - prefer_initializing_formals
+ - prefer_interpolation_to_compose_strings
+ #- prefer_single_quotes
+ - prefer_typing_uninitialized_variables
+ - slash_for_doc_comments
+ - test_types_in_equals
+ - super_goes_last
+ - test_types_in_equals
+ - throw_in_finally
+ - type_init_formals
+ - unnecessary_brace_in_string_interps
+ - unnecessary_const
+ - unnecessary_getters_setters
+ - unnecessary_lambdas
+ - unnecessary_new
+ - unnecessary_null_aware_assignments
+ - unnecessary_statements
+ #- unnecessary_this
diff --git a/lib/fixnum.dart b/lib/fixnum.dart
index fe21c47..6d08ba8 100644
--- a/lib/fixnum.dart
+++ b/lib/fixnum.dart
@@ -2,16 +2,14 @@
// 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.
-/**
- * Signed 32- and 64-bit integer support.
- *
- * The integer implementations in this library are designed to work
- * identically whether executed on the Dart VM or compiled to JavaScript.
- *
- * For information on installing and importing this library, see the
- * [fixnum package on pub.dartlang.org]
- * (http://pub.dartlang.org/packages/fixnum).
- */
+/// Signed 32- and 64-bit integer support.
+///
+/// The integer implementations in this library are designed to work
+/// identically whether executed on the Dart VM or compiled to JavaScript.
+///
+/// For information on installing and importing this library, see the
+/// [fixnum package on pub.dartlang.org]
+/// (http://pub.dartlang.org/packages/fixnum).
library fixnum;
part 'src/intx.dart';
diff --git a/lib/src/int32.dart b/lib/src/int32.dart
index db8ecd0..f3cc72c 100644
--- a/lib/src/int32.dart
+++ b/lib/src/int32.dart
@@ -4,37 +4,25 @@
part of fixnum;
-/**
- * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
- * Arithmetic operations may overflow in order to maintain this range.
- */
+/// An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
+/// Arithmetic operations may overflow in order to maintain this range.
class Int32 implements IntX {
- /**
- * The maximum positive value attainable by an [Int32], namely
- * 2147483647.
- */
- static const Int32 MAX_VALUE = const Int32._internal(0x7FFFFFFF);
+ /// The maximum positive value attainable by an [Int32], namely
+ /// 2147483647.
+ static const Int32 MAX_VALUE = Int32._internal(0x7FFFFFFF);
- /**
- * The minimum positive value attainable by an [Int32], namely
- * -2147483648.
- */
- static const Int32 MIN_VALUE = const Int32._internal(-0x80000000);
+ /// The minimum positive value attainable by an [Int32], namely
+ /// -2147483648.
+ static const Int32 MIN_VALUE = Int32._internal(-0x80000000);
- /**
- * An [Int32] constant equal to 0.
- */
- static const Int32 ZERO = const Int32._internal(0);
+ /// An [Int32] constant equal to 0.
+ static const Int32 ZERO = Int32._internal(0);
- /**
- * An [Int32] constant equal to 1.
- */
- static const Int32 ONE = const Int32._internal(1);
+ /// An [Int32] constant equal to 1.
+ static const Int32 ONE = Int32._internal(1);
- /**
- * An [Int32] constant equal to 2.
- */
- static const Int32 TWO = const Int32._internal(2);
+ /// An [Int32] constant equal to 2.
+ static const Int32 TWO = Int32._internal(2);
// Hex digit char codes
static const int _CC_0 = 48; // '0'.codeUnitAt(0)
@@ -58,13 +46,11 @@
static int _validateRadix(int radix) {
if (2 <= radix && radix <= 36) return radix;
- throw new RangeError.range(radix, 2, 36, 'radix');
+ throw RangeError.range(radix, 2, 36, 'radix');
}
- /**
- * Parses a [String] in a given [radix] between 2 and 16 and returns an
- * [Int32].
- */
+ /// Parses a [String] in a given [radix] between 2 and 16 and returns an
+ /// [Int32].
// TODO(rice) - Make this faster by converting several digits at once.
static Int32 parseRadix(String s, int radix) {
_validateRadix(radix);
@@ -73,21 +59,17 @@
int c = s.codeUnitAt(i);
int digit = _decodeDigit(c);
if (digit < 0 || digit >= radix) {
- throw new FormatException("Non-radix code unit: $c");
+ throw FormatException("Non-radix code unit: $c");
}
x = (x * radix) + digit;
}
return x;
}
- /**
- * Parses a decimal [String] and returns an [Int32].
- */
- static Int32 parseInt(String s) => new Int32(int.parse(s));
+ /// Parses a decimal [String] and returns an [Int32].
+ static Int32 parseInt(String s) => Int32(int.parse(s));
- /**
- * Parses a hexadecimal [String] and returns an [Int32].
- */
+ /// Parses a hexadecimal [String] and returns an [Int32].
static Int32 parseHex(String s) => parseRadix(s, 16);
// Assumes i is <= 32-bit.
@@ -134,10 +116,8 @@
const Int32._internal(int i) : _i = i;
- /**
- * Constructs an [Int32] from an [int]. Only the low 32 bits of the input
- * are used.
- */
+ /// Constructs an [Int32] from an [int]. Only the low 32 bits of the input
+ /// are used.
Int32([int i = 0]) : _i = (i & 0x7fffffff) - (i & 0x80000000);
// Returns the [int] representation of the specified value. Throws
@@ -148,7 +128,7 @@
} else if (val is int) {
return val;
}
- throw new ArgumentError(val);
+ throw ArgumentError(val);
}
// The +, -, * , &, |, and ^ operaters deal with types as follows:
@@ -169,17 +149,17 @@
if (other is Int64) {
return this.toInt64() + other;
}
- return new Int32(_i + _toInt(other));
+ return Int32(_i + _toInt(other));
}
IntX operator -(other) {
if (other is Int64) {
return this.toInt64() - other;
}
- return new Int32(_i - _toInt(other));
+ return Int32(_i - _toInt(other));
}
- Int32 operator -() => new Int32(-_i);
+ Int32 operator -() => Int32(-_i);
IntX operator *(other) {
if (other is Int64) {
@@ -194,14 +174,14 @@
// Result will be Int32
return (this.toInt64() % other).toInt32();
}
- return new Int32(_i % _toInt(other));
+ return Int32(_i % _toInt(other));
}
Int32 operator ~/(other) {
if (other is Int64) {
return (this.toInt64() ~/ other).toInt32();
}
- return new Int32(_i ~/ _toInt(other));
+ return Int32(_i ~/ _toInt(other));
}
Int32 remainder(other) {
@@ -216,38 +196,38 @@
if (other is Int64) {
return (this.toInt64() & other).toInt32();
}
- return new Int32(_i & _toInt(other));
+ return Int32(_i & _toInt(other));
}
Int32 operator |(other) {
if (other is Int64) {
return (this.toInt64() | other).toInt32();
}
- return new Int32(_i | _toInt(other));
+ return Int32(_i | _toInt(other));
}
Int32 operator ^(other) {
if (other is Int64) {
return (this.toInt64() ^ other).toInt32();
}
- return new Int32(_i ^ _toInt(other));
+ return Int32(_i ^ _toInt(other));
}
- Int32 operator ~() => new Int32(~_i);
+ Int32 operator ~() => Int32(~_i);
Int32 operator <<(int n) {
if (n < 0) {
- throw new ArgumentError(n);
+ throw ArgumentError(n);
}
if (n >= 32) {
return ZERO;
}
- return new Int32(_i << n);
+ return Int32(_i << n);
}
Int32 operator >>(int n) {
if (n < 0) {
- throw new ArgumentError(n);
+ throw ArgumentError(n);
}
if (n >= 32) {
return isNegative ? const Int32._internal(-1) : ZERO;
@@ -258,12 +238,12 @@
} else {
value = (_i >> n) | (0xffffffff << (32 - n));
}
- return new Int32(value);
+ return Int32(value);
}
Int32 shiftRightUnsigned(int n) {
if (n < 0) {
- throw new ArgumentError(n);
+ throw ArgumentError(n);
}
if (n >= 32) {
return ZERO;
@@ -274,13 +254,11 @@
} else {
value = (_i >> n) & ((1 << (32 - n)) - 1);
}
- return new Int32(value);
+ return Int32(value);
}
- /**
- * Returns [:true:] if this [Int32] has the same numeric value as the
- * given object. The argument may be an [int] or an [IntX].
- */
+ /// Returns [:true:] if this [Int32] has the same numeric value as the
+ /// given object. The argument may be an [int] or an [IntX].
bool operator ==(other) {
if (other is Int32) {
return _i == other._i;
@@ -337,17 +315,17 @@
int get hashCode => _i;
- Int32 abs() => _i < 0 ? new Int32(-_i) : this;
+ Int32 abs() => _i < 0 ? Int32(-_i) : this;
Int32 clamp(lowerLimit, upperLimit) {
if (this < lowerLimit) {
if (lowerLimit is IntX) return lowerLimit.toInt32();
- if (lowerLimit is int) return new Int32(lowerLimit);
- throw new ArgumentError(lowerLimit);
+ if (lowerLimit is int) return Int32(lowerLimit);
+ throw ArgumentError(lowerLimit);
} else if (this > upperLimit) {
if (upperLimit is IntX) return upperLimit.toInt32();
- if (upperLimit is int) return new Int32(upperLimit);
- throw new ArgumentError(upperLimit);
+ if (upperLimit is int) return Int32(upperLimit);
+ throw ArgumentError(upperLimit);
}
return this;
}
@@ -356,17 +334,17 @@
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);
Int32 toSigned(int width) {
- if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32);
- return new Int32(_i.toSigned(width));
+ if (width < 1 || width > 32) throw RangeError.range(width, 1, 32);
+ return Int32(_i.toSigned(width));
}
Int32 toUnsigned(int width) {
- if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32);
- return new Int32(_i.toUnsigned(width));
+ if (width < 0 || width > 32) throw RangeError.range(width, 0, 32);
+ return Int32(_i.toUnsigned(width));
}
List<int> toBytes() {
- List<int> result = new List<int>(4);
+ List<int> result = List<int>(4);
result[0] = _i & 0xff;
result[1] = (_i >> 8) & 0xff;
result[2] = (_i >> 16) & 0xff;
@@ -377,7 +355,7 @@
double toDouble() => _i.toDouble();
int toInt() => _i;
Int32 toInt32() => this;
- Int64 toInt64() => new Int64(_i);
+ Int64 toInt64() => Int64(_i);
String toString() => _i.toString();
String toHexString() => _i.toRadixString(16);
diff --git a/lib/src/int64.dart b/lib/src/int64.dart
index ead89fe..a1109c0 100644
--- a/lib/src/int64.dart
+++ b/lib/src/int64.dart
@@ -4,10 +4,8 @@
part of fixnum;
-/**
- * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1].
- * Arithmetic operations may overflow in order to maintain this range.
- */
+/// An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1].
+/// Arithmetic operations may overflow in order to maintain this range.
class Int64 implements IntX {
// A 64-bit integer is represented internally as three non-negative
// integers, storing the 22 low, 22 middle, and 20 high bits of the
@@ -31,43 +29,29 @@
static const int _SIGN_BIT = 19; // _BITS2 - 1
static const int _SIGN_BIT_MASK = 1 << _SIGN_BIT;
- /**
- * The maximum positive value attainable by an [Int64], namely
- * 9,223,372,036,854,775,807.
- */
- static const Int64 MAX_VALUE = const Int64._bits(_MASK, _MASK, _MASK2 >> 1);
+ /// The maximum positive value attainable by an [Int64], namely
+ /// 9,223,372,036,854,775,807.
+ static const Int64 MAX_VALUE = Int64._bits(_MASK, _MASK, _MASK2 >> 1);
- /**
- * The minimum positive value attainable by an [Int64], namely
- * -9,223,372,036,854,775,808.
- */
- static const Int64 MIN_VALUE = const Int64._bits(0, 0, _SIGN_BIT_MASK);
+ /// The minimum positive value attainable by an [Int64], namely
+ /// -9,223,372,036,854,775,808.
+ static const Int64 MIN_VALUE = Int64._bits(0, 0, _SIGN_BIT_MASK);
- /**
- * An [Int64] constant equal to 0.
- */
- static const Int64 ZERO = const Int64._bits(0, 0, 0);
+ /// An [Int64] constant equal to 0.
+ static const Int64 ZERO = Int64._bits(0, 0, 0);
- /**
- * An [Int64] constant equal to 1.
- */
- static const Int64 ONE = const Int64._bits(1, 0, 0);
+ /// An [Int64] constant equal to 1.
+ static const Int64 ONE = Int64._bits(1, 0, 0);
- /**
- * An [Int64] constant equal to 2.
- */
- static const Int64 TWO = const Int64._bits(2, 0, 0);
+ /// An [Int64] constant equal to 2.
+ static const Int64 TWO = Int64._bits(2, 0, 0);
- /**
- * Constructs an [Int64] with a given bitwise representation. No validation
- * is performed.
- */
+ /// Constructs an [Int64] with a given bitwise representation. No validation
+ /// is performed.
const Int64._bits(this._l, this._m, this._h);
- /**
- * Parses a [String] in a given [radix] between 2 and 36 and returns an
- * [Int64].
- */
+ /// Parses a [String] in a given [radix] between 2 and 36 and returns an
+ /// [Int64].
static Int64 parseRadix(String s, int radix) {
return _parseRadix(s, Int32._validateRadix(radix));
}
@@ -84,7 +68,7 @@
int c = s.codeUnitAt(i);
int digit = Int32._decodeDigit(c);
if (digit < 0 || digit >= radix) {
- throw new 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
@@ -106,23 +90,17 @@
return Int64._masked(d0, d1, d2);
}
- /**
- * Parses a decimal [String] and returns an [Int64].
- */
+ /// Parses a decimal [String] and returns an [Int64].
static Int64 parseInt(String s) => _parseRadix(s, 10);
- /**
- * Parses a hexadecimal [String] and returns an [Int64].
- */
+ /// Parses a hexadecimal [String] and returns an [Int64].
static Int64 parseHex(String s) => _parseRadix(s, 16);
//
// Public constructors
//
- /**
- * Constructs an [Int64] with a given [int] value; zero by default.
- */
+ /// Constructs an [Int64] with a given [int] value; zero by default.
factory Int64([int value = 0]) {
int v0 = 0, v1 = 0, v2 = 0;
bool negative = false;
@@ -160,7 +138,7 @@
bottom <<= 8;
bottom |= bytes[0] & 0xff;
- return new Int64.fromInts(top, bottom);
+ return Int64.fromInts(top, bottom);
}
factory Int64.fromBytesBigEndian(List<int> bytes) {
@@ -180,13 +158,11 @@
bottom <<= 8;
bottom |= bytes[7] & 0xff;
- return new Int64.fromInts(top, bottom);
+ return Int64.fromInts(top, bottom);
}
- /**
- * Constructs an [Int64] from a pair of 32-bit integers having the value
- * [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):].
- */
+ /// Constructs an [Int64] from a pair of 32-bit integers having the value
+ /// [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):].
factory Int64.fromInts(int top, int bottom) {
top &= 0xffffffff;
bottom &= 0xffffffff;
@@ -202,11 +178,11 @@
if (value is Int64) {
return value;
} else if (value is int) {
- return new Int64(value);
+ return Int64(value);
} else if (value is Int32) {
return value.toInt64();
}
- throw new ArgumentError.value(value);
+ throw ArgumentError.value(value);
}
Int64 operator +(other) {
@@ -341,7 +317,7 @@
Int64 operator <<(int n) {
if (n < 0) {
- throw new ArgumentError.value(n);
+ throw ArgumentError.value(n);
}
if (n >= 64) {
return ZERO;
@@ -367,7 +343,7 @@
Int64 operator >>(int n) {
if (n < 0) {
- throw new ArgumentError.value(n);
+ throw ArgumentError.value(n);
}
if (n >= 64) {
return isNegative ? const Int64._bits(_MASK, _MASK, _MASK2) : ZERO;
@@ -412,7 +388,7 @@
Int64 shiftRightUnsigned(int n) {
if (n < 0) {
- throw new ArgumentError.value(n);
+ throw ArgumentError.value(n);
}
if (n >= 64) {
return ZERO;
@@ -437,10 +413,8 @@
return Int64._masked(res0, res1, res2);
}
- /**
- * Returns [:true:] if this [Int64] has the same numeric value as the
- * given object. The argument may be an [int] or an [IntX].
- */
+ /// Returns [:true:] if this [Int64] has the same numeric value as the
+ /// given object. The argument may be an [int] or an [IntX].
bool operator ==(other) {
Int64 o;
if (other is Int64) {
@@ -450,7 +424,7 @@
// Since we know one of [_h] or [_m] is non-zero, if [other] fits in the
// low word then it can't be numerically equal.
if ((_MASK & other) == other) return false;
- o = new Int64(other);
+ o = Int64(other);
} else if (other is Int32) {
o = other.toInt64();
}
@@ -512,9 +486,7 @@
return a0.bitLength;
}
- /**
- * Returns a hash code based on all the bits of this [Int64].
- */
+ /// Returns a hash code based on all the bits of this [Int64].
int get hashCode {
// TODO(sra): Should we ensure that hashCode values match corresponding int?
// i.e. should `new Int64(x).hashCode == x.hashCode`?
@@ -535,10 +507,8 @@
return this;
}
- /**
- * Returns the number of leading zeros in this [Int64] as an [int]
- * between 0 and 64.
- */
+ /// Returns the number of leading zeros in this [Int64] as an [int]
+ /// between 0 and 64.
int numberOfLeadingZeros() {
int b2 = Int32._numberOfLeadingZeros(_h);
if (b2 == 32) {
@@ -553,10 +523,8 @@
}
}
- /**
- * Returns the number of trailing zeros in this [Int64] as an [int]
- * between 0 and 64.
- */
+ /// Returns the number of trailing zeros in this [Int64] as an [int]
+ /// between 0 and 64.
int numberOfTrailingZeros() {
int zeros = Int32._numberOfTrailingZeros(_l);
if (zeros < 32) {
@@ -577,7 +545,7 @@
}
Int64 toSigned(int width) {
- if (width < 1 || width > 64) throw new RangeError.range(width, 1, 64);
+ if (width < 1 || width > 64) throw RangeError.range(width, 1, 64);
if (width > _BITS01) {
return Int64._masked(_l, _m, _h.toSigned(width - _BITS01));
} else if (width > _BITS) {
@@ -594,7 +562,7 @@
}
Int64 toUnsigned(int width) {
- if (width < 0 || width > 64) throw new RangeError.range(width, 0, 64);
+ if (width < 0 || width > 64) throw RangeError.range(width, 0, 64);
if (width > _BITS01) {
int h = _h.toUnsigned(width - _BITS01);
return Int64._masked(_l, _m, h);
@@ -608,7 +576,7 @@
}
List<int> toBytes() {
- List<int> result = new List<int>(8);
+ List<int> result = List<int>(8);
result[0] = _l & 0xff;
result[1] = (_l >> 8) & 0xff;
result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f);
@@ -638,21 +606,15 @@
}
}
- /**
- * Returns an [Int32] containing the low 32 bits of this [Int64].
- */
+ /// Returns an [Int32] containing the low 32 bits of this [Int64].
Int32 toInt32() {
- return new Int32(((_m & 0x3ff) << _BITS) | _l);
+ return Int32(((_m & 0x3ff) << _BITS) | _l);
}
- /**
- * Returns [this].
- */
+ /// Returns `this`.
Int64 toInt64() => this;
- /**
- * Returns the value of this [Int64] as a decimal [String].
- */
+ /// Returns the value of this [Int64] as a decimal [String].
String toString() => _toRadixString(10);
// TODO(rice) - Make this faster by avoiding arithmetic.
@@ -668,9 +630,7 @@
return hexStr;
}
- /**
- * Returns the digits of [this] when interpreted as an unsigned 64-bit value.
- */
+ /// Returns the digits of `this` when interpreted as an unsigned 64-bit value.
@pragma('dart2js:noInline')
String toStringUnsigned() {
return _toRadixStringUnsigned(10, _l, _m, _h, '');
@@ -787,7 +747,7 @@
// Table of 'fat' radix values. Each entry for index `i` is the largest power
// of `i` whose remainder fits in 20 bits.
- static const _fatRadixTable = const <int>[
+ static const _fatRadixTable = <int>[
0,
0,
2 *
@@ -851,7 +811,7 @@
}
static Int64 _masked(int a0, int a1, int a2) =>
- new Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2);
+ Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2);
static Int64 _sub(int a0, int a1, int a2, int b0, int b1, int b2) {
int diff0 = a0 - b0;
@@ -884,7 +844,7 @@
static Int64 _divide(Int64 a, other, int what) {
Int64 b = _promote(other);
if (b.isZero) {
- throw new IntegerDivisionByZeroException();
+ throw const IntegerDivisionByZeroException();
}
if (a.isZero) return ZERO;
@@ -1014,9 +974,9 @@
}
// 0 <= R < B
- assert(Int64.ZERO <= new Int64._bits(r0, r1, r2));
+ assert(Int64.ZERO <= Int64._bits(r0, r1, r2));
assert(r2 < b2 || // Handles case where B = -(MIN_VALUE)
- new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2));
+ Int64._bits(r0, r1, r2) < Int64._bits(b0, b1, b2));
assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM);
if (what == _RETURN_DIV) {
diff --git a/lib/src/intx.dart b/lib/src/intx.dart
index 3c2207d..cdc4b05 100644
--- a/lib/src/intx.dart
+++ b/lib/src/intx.dart
@@ -4,233 +4,189 @@
part of fixnum;
-/**
- * A fixed-precision integer.
- */
+/// A fixed-precision integer.
abstract class IntX implements Comparable<dynamic> {
- /** Addition operator. */
+ /// Addition operator.
IntX operator +(other);
- /** Subtraction operator. */
+ /// Subtraction operator.
IntX operator -(other);
- /**
- * Negate operator.
- *
- * Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow.
- */
+ /// Negate operator.
+ ///
+ /// Note that `-MIN_VALUE` is equal to `MIN_VALUE` due to overflow.
IntX operator -();
- /** Multiplication operator. */
+ /// Multiplication operator.
IntX operator *(other);
- /**
- * Euclidean modulo operator.
- *
- * Returns the remainder of the euclidean division. The euclidean division
- * of two integers `a` and `b` yields two integers `q` and `r` such that
- * `a == b * q + r` and `0 <= r < a.abs()`.
- */
+ /// Euclidean modulo operator.
+ ///
+ /// Returns the remainder of the euclidean division. The euclidean division
+ /// of two integers `a` and `b` yields two integers `q` and `r` such that
+ /// `a == b * q + r` and `0 <= r < a.abs()`.
IntX operator %(other);
- /** Truncating division operator. */
+ /// Truncating division operator.
IntX operator ~/(other);
- /**
- * Returns the remainder of the truncating division of this integer by
- * [other].
- */
+ /// Returns the remainder of the truncating division of this integer by
+ /// [other].
IntX remainder(other);
- /** Bitwise and operator. */
+ /// Bitwise and operator.
IntX operator &(other);
- /** Bitwise or operator. */
+ /// Bitwise or operator.
IntX operator |(other);
- /** Bitwise xor operator. */
+ /// Bitwise xor operator.
IntX operator ^(other);
- /** Bitwise negate operator. */
+ /// Bitwise negate operator.
IntX operator ~();
- /**
- * Left bit-shift operator.
- *
- * Returns the result of shifting the bits of this integer by [shiftAmount]
- * bits to the left. Low-order bits are filled with zeros.
- */
+ /// Left bit-shift operator.
+ ///
+ /// Returns the result of shifting the bits of this integer by [shiftAmount]
+ /// bits to the left. Low-order bits are filled with zeros.
IntX operator <<(int shiftAmount);
- /**
- * Right bit-shift operator.
- *
- * Returns the result of shifting the bits of this integer by [shiftAmount]
- * bits to the right. High-order bits are filled with zero in the case where
- * this integer is positive, or one in the case where it is negative.
- */
+ /// Right bit-shift operator.
+ ///
+ /// Returns the result of shifting the bits of this integer by [shiftAmount]
+ /// bits to the right. High-order bits are filled with zero in the case where
+ /// this integer is positive, or one in the case where it is negative.
IntX operator >>(int shiftAmount);
- /**
- * Unsigned right-shift operator.
- *
- * Returns the result of shifting the bits of this integer by [shiftAmount]
- * bits to the right. High-order bits are filled with zeros.
- */
+ /// Unsigned right-shift operator.
+ ///
+ /// Returns the result of shifting the bits of this integer by [shiftAmount]
+ /// bits to the right. High-order bits are filled with zeros.
IntX shiftRightUnsigned(int shiftAmount);
int compareTo(other);
- /**
- * Returns `true` if and only if [other] is an int or IntX equal in
- * value to this integer.
- */
+ /// Returns `true` if and only if [other] is an int or IntX equal in
+ /// value to this integer.
bool operator ==(other);
- /** Relational less than operator. */
+ /// Relational less than operator.
bool operator <(other);
- /** Relational less than or equal to operator. */
+ /// Relational less than or equal to operator.
bool operator <=(other);
- /** Relational greater than operator. */
+ /// Relational greater than operator.
bool operator >(other);
- /** Relational greater than or equal to operator. */
+ /// Relational greater than or equal to operator.
bool operator >=(other);
- /** Returns `true` if and only if this integer is even. */
+ /// Returns `true` if and only if this integer is even.
bool get isEven;
- /**
- * Returns `true` if and only if this integer is the maximum signed value
- * that can be represented within its bit size.
- */
+ /// Returns `true` if and only if this integer is the maximum signed value
+ /// that can be represented within its bit size.
bool get isMaxValue;
- /**
- * Returns `true` if and only if this integer is the minimum signed value
- * that can be represented within its bit size.
- */
+ /// Returns `true` if and only if this integer is the minimum signed value
+ /// that can be represented within its bit size.
bool get isMinValue;
- /** Returns `true` if and only if this integer is less than zero. */
+ /// Returns `true` if and only if this integer is less than zero.
bool get isNegative;
- /** Returns `true` if and only if this integer is odd. */
+ /// Returns `true` if and only if this integer is odd.
bool get isOdd;
- /** Returns `true` if and only if this integer is zero. */
+ /// Returns `true` if and only if this integer is zero.
bool get isZero;
int get hashCode;
- /** Returns the absolute value of this integer. */
+ /// Returns the absolute value of this integer.
IntX abs();
- /** Clamps this integer to be in the range [lowerLimit] - [upperLimit]. */
+ /// Clamps this integer to be in the range [lowerLimit] - [upperLimit].
IntX clamp(lowerLimit, upperLimit);
- /**
- * Returns the minimum number of bits required to store this integer.
- *
- * The number of bits excludes the sign bit, which gives the natural length
- * for non-negative (unsigned) values. Negative values are complemented to
- * return the bit position of the first bit that differs from the sign bit.
- *
- * To find the the number of bits needed to store the value as a signed value,
- * add one, i.e. use `x.bitLength + 1`.
- */
+ /// Returns the minimum number of bits required to store this integer.
+ ///
+ /// The number of bits excludes the sign bit, which gives the natural length
+ /// for non-negative (unsigned) values. Negative values are complemented to
+ /// return the bit position of the first bit that differs from the sign bit.
+ ///
+ /// To find the the number of bits needed to store the value as a signed value,
+ /// add one, i.e. use `x.bitLength + 1`.
int get bitLength;
- /**
- * Returns the number of high-order zeros in this integer's bit
- * representation.
- */
+ /// Returns the number of high-order zeros in this integer's bit
+ /// representation.
int numberOfLeadingZeros();
- /**
- * Returns the number of low-order zeros in this integer's bit representation.
- */
+ /// Returns the number of low-order zeros in this integer's bit representation.
int numberOfTrailingZeros();
- /**
- * Returns the least significant [width] bits of this integer, extending the
- * highest retained bit to the sign. This is the same as truncating the value
- * to fit in [width] bits using an signed 2-s complement representation. The
- * returned value has the same bit value in all positions higher than [width].
- *
- * If the input value fits in [width] bits without truncation, the result is
- * the same as the input. The minimum width needed to avoid truncation of `x`
- * is `x.bitLength + 1`, i.e.
- *
- * x == x.toSigned(x.bitLength + 1);
- */
+ /// Returns the least significant [width] bits of this integer, extending the
+ /// highest retained bit to the sign. This is the same as truncating the value
+ /// to fit in [width] bits using an signed 2-s complement representation. The
+ /// returned value has the same bit value in all positions higher than [width].
+ ///
+ /// If the input value fits in [width] bits without truncation, the result is
+ /// the same as the input. The minimum width needed to avoid truncation of `x`
+ /// is `x.bitLength + 1`, i.e.
+ ///
+ /// x == x.toSigned(x.bitLength + 1);
IntX toSigned(int width);
- /**
- * Returns the least significant [width] bits of this integer as a
- * non-negative number (i.e. unsigned representation). The returned value has
- * zeros in all bit positions higher than [width].
- *
- * If the input fits in [width] bits without truncation, the result is the
- * same as the input. The minimum width needed to avoid truncation of `x` is
- * given by `x.bitLength`, i.e.
- *
- * x == x.toUnsigned(x.bitLength);
- */
+ /// Returns the least significant [width] bits of this integer as a
+ /// non-negative number (i.e. unsigned representation). The returned value has
+ /// zeros in all bit positions higher than [width].
+ ///
+ /// If the input fits in [width] bits without truncation, the result is the
+ /// same as the input. The minimum width needed to avoid truncation of `x` is
+ /// given by `x.bitLength`, i.e.
+ ///
+ /// x == x.toUnsigned(x.bitLength);
IntX toUnsigned(int width);
- /**
- * Returns a byte-sequence representation of this integer.
- *
- * Returns a list of int, starting with the least significant byte.
- */
+ /// Returns a byte-sequence representation of this integer.
+ ///
+ /// Returns a list of int, starting with the least significant byte.
List<int> toBytes();
- /**
- * Returns the double representation of this integer.
- *
- * On some platforms, inputs with large absolute values (i.e., > 2^52) may
- * lose some of their low-order bits.
- */
+ /// Returns the double representation of this integer.
+ ///
+ /// On some platforms, inputs with large absolute values (i.e., > 2^52) may
+ /// lose some of their low-order bits.
double toDouble();
- /**
- * Returns the int representation of this integer.
- *
- * On some platforms, inputs with large absolute values (i.e., > 2^52) may
- * lose some of their low-order bits.
- */
+ /// Returns the int representation of this integer.
+ ///
+ /// On some platforms, inputs with large absolute values (i.e., > 2^52) may
+ /// lose some of their low-order bits.
int toInt();
- /**
- * Returns an Int32 representation of this integer.
- *
- * Narrower values are sign-extended and wider values have their high bits
- * truncated.
- */
+ /// Returns an Int32 representation of this integer.
+ ///
+ /// Narrower values are sign-extended and wider values have their high bits
+ /// truncated.
Int32 toInt32();
- /** Returns an Int64 representation of this integer. */
+ /// Returns an Int64 representation of this integer.
Int64 toInt64();
- /**
- * Returns a string representing the value of this integer in decimal
- * notation; example: `'13'`.
- */
+ /// Returns a string representing the value of this integer in decimal
+ /// notation; example: `'13'`.
String toString();
- /**
- * Returns a string representing the value of this integer in hexadecimal
- * notation; example: `'0xd'`.
- */
+ /// Returns a string representing the value of this integer in hexadecimal
+ /// notation; example: `'0xd'`.
String toHexString();
- /**
- * Returns a string representing the value of this integer in the given radix.
- *
- * [radix] must be an integer in the range 2 .. 16, inclusive.
- */
+ /// Returns a string representing the value of this integer in the given radix.
+ ///
+ /// [radix] must be an integer in the range 2 .. 16, inclusive.
String toRadixString(int radix);
}
diff --git a/pubspec.yaml b/pubspec.yaml
index ff06246..db003b8 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -6,7 +6,8 @@
homepage: https://github.com/dart-lang/fixnum
environment:
- sdk: '>=2.0.0-dev.65 <3.0.0'
+ sdk: '>=2.0.0 <3.0.0'
dev_dependencies:
+ pedantic: ^1.3.0
test: ^1.2.0
diff --git a/test/int32_test.dart b/test/int32_test.dart
index 5598638..e76a0dc 100644
--- a/test/int32_test.dart
+++ b/test/int32_test.dart
@@ -2,8 +2,6 @@
// 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.
-library Int32test;
-
import 'package:fixnum/fixnum.dart';
import 'package:test/test.dart';
@@ -42,123 +40,117 @@
expect(Int32.MAX_VALUE.isZero, false);
});
test("bitLength", () {
- expect(new Int32(-2).bitLength, 1);
+ expect(Int32(-2).bitLength, 1);
expect((-Int32.ONE).bitLength, 0);
expect(Int32.ZERO.bitLength, 0);
expect(Int32.ONE.bitLength, 1);
- expect(new Int32(2).bitLength, 2);
+ expect(Int32(2).bitLength, 2);
expect(Int32.MAX_VALUE.bitLength, 31);
expect(Int32.MIN_VALUE.bitLength, 31);
});
});
group("arithmetic operators", () {
- Int32 n1 = new Int32(1234);
- Int32 n2 = new Int32(9876);
- Int32 n3 = new Int32(-1234);
- Int32 n4 = new Int32(-9876);
+ Int32 n1 = Int32(1234);
+ Int32 n2 = Int32(9876);
+ Int32 n3 = Int32(-1234);
+ Int32 n4 = Int32(-9876);
test("+", () {
- expect(n1 + n2, new Int32(11110));
- expect(n3 + n2, new Int32(8642));
- expect(n3 + n4, new Int32(-11110));
- expect(n3 + new Int64(1), new Int64(-1233));
+ expect(n1 + n2, Int32(11110));
+ expect(n3 + n2, Int32(8642));
+ expect(n3 + n4, Int32(-11110));
+ expect(n3 + Int64(1), Int64(-1233));
expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE);
- expect(() => new Int32(17) + null, throwsArgumentError);
+ expect(() => Int32(17) + null, throwsArgumentError);
});
test("-", () {
- expect(n1 - n2, new Int32(-8642));
- expect(n3 - n2, new Int32(-11110));
- expect(n3 - n4, new Int32(8642));
- expect(n3 - new Int64(1), new Int64(-1235));
+ expect(n1 - n2, Int32(-8642));
+ expect(n3 - n2, Int32(-11110));
+ expect(n3 - n4, Int32(8642));
+ expect(n3 - Int64(1), Int64(-1235));
expect(Int32.MIN_VALUE - 1, Int32.MAX_VALUE);
- expect(() => new Int32(17) - null, throwsArgumentError);
+ expect(() => Int32(17) - null, throwsArgumentError);
});
test("unary -", () {
- expect(-n1, new Int32(-1234));
+ expect(-n1, Int32(-1234));
expect(-Int32.ZERO, Int32.ZERO);
});
test("*", () {
- 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(123456789) * 987654321), new Int32(-67153019));
- expect(() => new Int32(17) * null, throwsArgumentError);
+ expect(n1 * n2, Int32(12186984));
+ expect(n2 * n3, Int32(-12186984));
+ expect(n3 * n3, Int32(1522756));
+ expect(n3 * n2, Int32(-12186984));
+ expect(Int32(0x12345678) * Int32(0x22222222), Int32(-899716112));
+ expect((Int32(123456789) * Int32(987654321)), Int32(-67153019));
+ expect(Int32(0x12345678) * Int64(0x22222222),
+ Int64.fromInts(0x026D60DC, 0xCA5F6BF0));
+ expect((Int32(123456789) * 987654321), Int32(-67153019));
+ expect(() => Int32(17) * null, throwsArgumentError);
});
test("~/", () {
- 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(Int32(829893893) ~/ Int32(1919), Int32(432461));
+ expect(Int32(0x12345678) ~/ Int32(0x22), Int32(0x12345678 ~/ 0x22));
+ expect(Int32(829893893) ~/ Int64(1919), Int32(432461));
+ expect(Int32(0x12345678) ~/ Int64(0x22), Int32(0x12345678 ~/ 0x22));
+ expect(Int32(829893893) ~/ 1919, Int32(432461));
expect(
- () => new Int32(17) ~/ Int32.ZERO,
+ () => Int32(17) ~/ Int32.ZERO,
// with dart2js, `UnsupportedError` is thrown
// on the VM: IntegerDivisionByZeroException
- throwsA(anyOf(new TypeMatcher<IntegerDivisionByZeroException>(),
+ throwsA(anyOf(const TypeMatcher<IntegerDivisionByZeroException>(),
isUnsupportedError)));
- expect(() => new Int32(17) ~/ null, throwsArgumentError);
+ expect(() => Int32(17) ~/ null, throwsArgumentError);
});
test("%", () {
- 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, throwsArgumentError);
+ expect(Int32(0x12345678) % Int32(0x22), Int32(0x12345678 % 0x22));
+ expect(Int32(0x12345678) % Int64(0x22), Int32(0x12345678 % 0x22));
+ expect(() => Int32(17) % null, throwsArgumentError);
});
test("remainder", () {
- 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), throwsArgumentError);
+ expect(Int32(0x12345678).remainder(Int32(0x22)),
+ Int32(0x12345678.remainder(0x22)));
+ expect(Int32(0x12345678).remainder(Int32(-0x22)),
+ Int32(0x12345678.remainder(-0x22)));
+ expect(Int32(-0x12345678).remainder(Int32(-0x22)),
+ Int32(-0x12345678.remainder(-0x22)));
+ expect(Int32(-0x12345678).remainder(Int32(0x22)),
+ Int32(-0x12345678.remainder(0x22)));
+ expect(Int32(0x12345678).remainder(Int64(0x22)),
+ Int32(0x12345678.remainder(0x22)));
+ expect(() => Int32(17).remainder(null), throwsArgumentError);
});
test("abs", () {
// NOTE: Int32.MIN_VALUE.abs() is undefined
expect((Int32.MIN_VALUE + 1).abs(), Int32.MAX_VALUE);
- expect(new Int32(-1).abs(), new Int32(1));
- expect(new Int32(0).abs(), new Int32(0));
- expect(new Int32(1).abs(), new Int32(1));
+ expect(Int32(-1).abs(), Int32(1));
+ expect(Int32(0).abs(), Int32(0));
+ expect(Int32(1).abs(), Int32(1));
expect(Int32.MAX_VALUE.abs(), Int32.MAX_VALUE);
});
test("clamp", () {
- Int32 val = new Int32(17);
- expect(val.clamp(20, 30), new Int32(20));
- expect(val.clamp(10, 20), new Int32(17));
- expect(val.clamp(10, 15), new Int32(15));
+ Int32 val = Int32(17);
+ expect(val.clamp(20, 30), Int32(20));
+ expect(val.clamp(10, 20), Int32(17));
+ expect(val.clamp(10, 15), Int32(15));
- expect(val.clamp(new Int32(20), new Int32(30)), new Int32(20));
- expect(val.clamp(new Int32(10), new Int32(20)), new Int32(17));
- expect(val.clamp(new Int32(10), new Int32(15)), new Int32(15));
+ expect(val.clamp(Int32(20), Int32(30)), Int32(20));
+ expect(val.clamp(Int32(10), Int32(20)), Int32(17));
+ expect(val.clamp(Int32(10), Int32(15)), Int32(15));
- expect(val.clamp(new Int64(20), new Int64(30)), new Int32(20));
- expect(val.clamp(new Int64(10), new Int64(20)), new Int32(17));
- expect(val.clamp(new Int64(10), new Int64(15)), new Int32(15));
- expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int32(17));
- expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int32(17));
+ expect(val.clamp(Int64(20), Int64(30)), Int32(20));
+ expect(val.clamp(Int64(10), Int64(20)), Int32(17));
+ expect(val.clamp(Int64(10), Int64(15)), Int32(15));
+ expect(val.clamp(Int64.MIN_VALUE, Int64(30)), Int32(17));
+ expect(val.clamp(Int64(10), Int64.MAX_VALUE), Int32(17));
expect(() => val.clamp(30.5, 40.5), throwsArgumentError);
expect(() => val.clamp(5.5, 10.5), throwsArgumentError);
@@ -170,156 +162,155 @@
group("leading/trailing zeros", () {
test("numberOfLeadingZeros", () {
- expect(new Int32(0).numberOfLeadingZeros(), 32);
- expect(new Int32(1).numberOfLeadingZeros(), 31);
- expect(new Int32(0xffff).numberOfLeadingZeros(), 16);
- expect(new Int32(-1).numberOfLeadingZeros(), 0);
+ expect(Int32(0).numberOfLeadingZeros(), 32);
+ expect(Int32(1).numberOfLeadingZeros(), 31);
+ expect(Int32(0xffff).numberOfLeadingZeros(), 16);
+ expect(Int32(-1).numberOfLeadingZeros(), 0);
});
test("numberOfTrailingZeros", () {
- expect(new Int32(0).numberOfTrailingZeros(), 32);
- expect(new Int32(0x80000000).numberOfTrailingZeros(), 31);
- expect(new Int32(1).numberOfTrailingZeros(), 0);
- expect(new Int32(0x10000).numberOfTrailingZeros(), 16);
+ expect(Int32(0).numberOfTrailingZeros(), 32);
+ expect(Int32(0x80000000).numberOfTrailingZeros(), 31);
+ expect(Int32(1).numberOfTrailingZeros(), 0);
+ expect(Int32(0x10000).numberOfTrailingZeros(), 16);
});
});
group("comparison operators", () {
test("compareTo", () {
- expect(new Int32(0).compareTo(-1), 1);
- expect(new Int32(0).compareTo(0), 0);
- expect(new Int32(0).compareTo(1), -1);
- expect(new Int32(0).compareTo(new Int32(-1)), 1);
- expect(new Int32(0).compareTo(new Int32(0)), 0);
- expect(new Int32(0).compareTo(new Int32(1)), -1);
- expect(new Int32(0).compareTo(new Int64(-1)), 1);
- expect(new Int32(0).compareTo(new Int64(0)), 0);
- expect(new Int32(0).compareTo(new Int64(1)), -1);
+ expect(Int32(0).compareTo(-1), 1);
+ expect(Int32(0).compareTo(0), 0);
+ expect(Int32(0).compareTo(1), -1);
+ expect(Int32(0).compareTo(Int32(-1)), 1);
+ expect(Int32(0).compareTo(Int32(0)), 0);
+ expect(Int32(0).compareTo(Int32(1)), -1);
+ expect(Int32(0).compareTo(Int64(-1)), 1);
+ expect(Int32(0).compareTo(Int64(0)), 0);
+ expect(Int32(0).compareTo(Int64(1)), -1);
});
test("<", () {
- 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(17) < Int32(18), true);
+ expect(Int32(17) < Int32(17), false);
+ expect(Int32(17) < Int32(16), false);
+ expect(Int32(17) < Int64(18), true);
+ expect(Int32(17) < Int64(17), false);
+ expect(Int32(17) < Int64(16), false);
expect(Int32.MIN_VALUE < Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE < Int32.MIN_VALUE, false);
- expect(() => new Int32(17) < null, throwsArgumentError);
+ expect(() => Int32(17) < null, throwsArgumentError);
});
test("<=", () {
- 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(17) <= Int32(18), true);
+ expect(Int32(17) <= Int32(17), true);
+ expect(Int32(17) <= Int32(16), false);
+ expect(Int32(17) <= Int64(18), true);
+ expect(Int32(17) <= Int64(17), true);
+ expect(Int32(17) <= Int64(16), false);
expect(Int32.MIN_VALUE <= Int32.MAX_VALUE, true);
expect(Int32.MAX_VALUE <= Int32.MIN_VALUE, false);
- expect(() => new Int32(17) <= null, throwsArgumentError);
+ expect(() => Int32(17) <= null, throwsArgumentError);
});
test("==", () {
- 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(17) == Int32(18), false);
+ expect(Int32(17) == Int32(17), true);
+ expect(Int32(17) == Int32(16), false);
+ expect(Int32(17) == Int64(18), false);
+ expect(Int32(17) == Int64(17), true);
+ expect(Int32(17) == Int64(16), false);
expect(Int32.MIN_VALUE == Int32.MAX_VALUE, false);
- expect(new Int32(17) == 18, false);
- expect(new Int32(17) == 17, true);
- expect(new Int32(17) == 16, false);
- expect(new Int32(17) == new Object(), false);
- expect(new Int32(17) == null, false);
+ expect(Int32(17) == 18, false);
+ expect(Int32(17) == 17, true);
+ expect(Int32(17) == 16, false);
+ expect(Int32(17) == Object(), false);
+ expect(Int32(17) == null, false);
});
test(">=", () {
- 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(17) >= Int32(18), false);
+ expect(Int32(17) >= Int32(17), true);
+ expect(Int32(17) >= Int32(16), true);
+ expect(Int32(17) >= Int64(18), false);
+ expect(Int32(17) >= Int64(17), true);
+ expect(Int32(17) >= Int64(16), true);
expect(Int32.MIN_VALUE >= Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE >= Int32.MIN_VALUE, true);
- expect(() => new Int32(17) >= null, throwsArgumentError);
+ expect(() => Int32(17) >= null, throwsArgumentError);
});
test(">", () {
- 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(17) > Int32(18), false);
+ expect(Int32(17) > Int32(17), false);
+ expect(Int32(17) > Int32(16), true);
+ expect(Int32(17) > Int64(18), false);
+ expect(Int32(17) > Int64(17), false);
+ expect(Int32(17) > Int64(16), true);
expect(Int32.MIN_VALUE > Int32.MAX_VALUE, false);
expect(Int32.MAX_VALUE > Int32.MIN_VALUE, true);
- expect(() => new Int32(17) > null, throwsArgumentError);
+ expect(() => Int32(17) > null, throwsArgumentError);
});
});
group("bitwise operators", () {
test("&", () {
- 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);
+ expect(Int32(0x12345678) & Int32(0x22222222),
+ Int32(0x12345678 & 0x22222222));
+ expect(Int32(0x12345678) & Int64(0x22222222),
+ Int64(0x12345678 & 0x22222222));
+ expect(() => Int32(17) & null, throwsArgumentError);
});
test("|", () {
- 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);
+ expect(Int32(0x12345678) | Int32(0x22222222),
+ Int32(0x12345678 | 0x22222222));
+ expect(Int32(0x12345678) | Int64(0x22222222),
+ Int64(0x12345678 | 0x22222222));
+ expect(() => Int32(17) | null, throwsArgumentError);
});
test("^", () {
- 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);
+ expect(Int32(0x12345678) ^ Int32(0x22222222),
+ Int32(0x12345678 ^ 0x22222222));
+ expect(Int32(0x12345678) ^ Int64(0x22222222),
+ Int64(0x12345678 ^ 0x22222222));
+ expect(() => Int32(17) ^ null, throwsArgumentError);
});
test("~", () {
- expect(~(new Int32(0x12345678)), new Int32(~0x12345678));
- expect(-(new Int32(0x12345678)), new Int64(-0x12345678));
+ expect(~(Int32(0x12345678)), Int32(~0x12345678));
+ expect(-(Int32(0x12345678)), Int64(-0x12345678));
});
});
group("bitshift operators", () {
test("<<", () {
- expect(new Int32(0x12345678) << 7, new Int32(0x12345678 << 7));
- expect(new Int32(0x12345678) << 32, Int32.ZERO);
- expect(new Int32(0x12345678) << 33, Int32.ZERO);
- expect(() => new Int32(17) << -1, throwsArgumentError);
- expect(() => new Int32(17) << null, throwsNoSuchMethodError);
+ expect(Int32(0x12345678) << 7, Int32(0x12345678 << 7));
+ expect(Int32(0x12345678) << 32, Int32.ZERO);
+ expect(Int32(0x12345678) << 33, Int32.ZERO);
+ expect(() => Int32(17) << -1, throwsArgumentError);
+ expect(() => Int32(17) << null, throwsNoSuchMethodError);
});
test(">>", () {
- expect(new Int32(0x12345678) >> 7, new Int32(0x12345678 >> 7));
- expect(new Int32(0x12345678) >> 32, Int32.ZERO);
- expect(new Int32(0x12345678) >> 33, Int32.ZERO);
- expect(new Int32(-42) >> 32, new Int32(-1));
- expect(new Int32(-42) >> 33, new Int32(-1));
- expect(() => new Int32(17) >> -1, throwsArgumentError);
- expect(() => new Int32(17) >> null, throwsNoSuchMethodError);
+ expect(Int32(0x12345678) >> 7, Int32(0x12345678 >> 7));
+ expect(Int32(0x12345678) >> 32, Int32.ZERO);
+ expect(Int32(0x12345678) >> 33, Int32.ZERO);
+ expect(Int32(-42) >> 32, Int32(-1));
+ expect(Int32(-42) >> 33, Int32(-1));
+ expect(() => Int32(17) >> -1, throwsArgumentError);
+ expect(() => Int32(17) >> null, throwsNoSuchMethodError);
});
test("shiftRightUnsigned", () {
- expect(new Int32(0x12345678).shiftRightUnsigned(7),
- new Int32(0x12345678 >> 7));
- expect(new Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO);
- expect(new Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO);
- expect(new Int32(-42).shiftRightUnsigned(32), Int32.ZERO);
- expect(new Int32(-42).shiftRightUnsigned(33), Int32.ZERO);
- expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
- expect(() => (new Int32(17).shiftRightUnsigned(null)),
- throwsNoSuchMethodError);
+ expect(Int32(0x12345678).shiftRightUnsigned(7), Int32(0x12345678 >> 7));
+ expect(Int32(0x12345678).shiftRightUnsigned(32), Int32.ZERO);
+ expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO);
+ expect(Int32(-42).shiftRightUnsigned(32), Int32.ZERO);
+ expect(Int32(-42).shiftRightUnsigned(33), Int32.ZERO);
+ expect(() => (Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
+ expect(
+ () => (Int32(17).shiftRightUnsigned(null)), throwsNoSuchMethodError);
});
});
@@ -345,33 +336,33 @@
expect(() => Int32.ONE.toUnsigned(33), throwsRangeError);
});
test("toDouble", () {
- expect(new Int32(17).toDouble(), same(17.0));
- expect(new Int32(-17).toDouble(), same(-17.0));
+ expect(Int32(17).toDouble(), same(17.0));
+ expect(Int32(-17).toDouble(), same(-17.0));
});
test("toInt", () {
- expect(new Int32(17).toInt(), 17);
- expect(new Int32(-17).toInt(), -17);
+ expect(Int32(17).toInt(), 17);
+ expect(Int32(-17).toInt(), -17);
});
test("toInt32", () {
- expect(new Int32(17).toInt32(), new Int32(17));
- expect(new Int32(-17).toInt32(), new Int32(-17));
+ expect(Int32(17).toInt32(), Int32(17));
+ expect(Int32(-17).toInt32(), Int32(-17));
});
test("toInt64", () {
- expect(new Int32(17).toInt64(), new Int64(17));
- expect(new Int32(-17).toInt64(), new Int64(-17));
+ expect(Int32(17).toInt64(), Int64(17));
+ expect(Int32(-17).toInt64(), Int64(-17));
});
test("toBytes", () {
- expect(new Int32(0).toBytes(), [0, 0, 0, 0]);
- expect(new Int32(0x01020304).toBytes(), [4, 3, 2, 1]);
- expect(new Int32(0x04030201).toBytes(), [1, 2, 3, 4]);
- expect(new Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]);
+ expect(Int32(0).toBytes(), [0, 0, 0, 0]);
+ expect(Int32(0x01020304).toBytes(), [4, 3, 2, 1]);
+ expect(Int32(0x04030201).toBytes(), [1, 2, 3, 4]);
+ expect(Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]);
});
});
group("parse", () {
test("base 10", () {
checkInt(int x) {
- expect(Int32.parseRadix('$x', 10), new Int32(x));
+ expect(Int32.parseRadix('$x', 10), Int32(x));
}
checkInt(0);
@@ -396,49 +387,49 @@
});
test("parseInt", () {
- expect(Int32.parseInt('0'), new Int32(0));
- expect(Int32.parseInt('1000'), new Int32(1000));
- expect(Int32.parseInt('4294967296'), new Int32(4294967296));
+ expect(Int32.parseInt('0'), Int32(0));
+ expect(Int32.parseInt('1000'), Int32(1000));
+ expect(Int32.parseInt('4294967296'), Int32(4294967296));
});
test("parseHex", () {
- expect(Int32.parseHex('deadbeef'), new Int32(0xdeadbeef));
- expect(Int32.parseHex('cafebabe'), new Int32(0xcafebabe));
- expect(Int32.parseHex('8badf00d'), new Int32(0x8badf00d));
+ expect(Int32.parseHex('deadbeef'), Int32(0xdeadbeef));
+ expect(Int32.parseHex('cafebabe'), Int32(0xcafebabe));
+ expect(Int32.parseHex('8badf00d'), Int32(0x8badf00d));
});
});
group("string representation", () {
test("toString", () {
- 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");
+ 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(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");
+ 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(new Int32(123456789).toRadixString(5), "223101104124");
+ expect(Int32(123456789).toRadixString(5), "223101104124");
});
});
}
diff --git a/test/int64_test.dart b/test/int64_test.dart
index 0fc2085..ac6b6b0 100644
--- a/test/int64_test.dart
+++ b/test/int64_test.dart
@@ -11,7 +11,7 @@
group("fromBytes", () {
test("fromBytes", () {
checkBytes(List<int> bytes, int h, int l) {
- expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l));
+ expect(Int64.fromBytes(bytes), Int64.fromInts(h, l));
}
checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0);
@@ -24,7 +24,7 @@
});
test("fromBytesBigEndian", () {
checkBytes(List<int> bytes, int h, int l) {
- expect(new Int64.fromBytesBigEndian(bytes), new Int64.fromInts(h, l));
+ expect(Int64.fromBytesBigEndian(bytes), Int64.fromInts(h, l));
}
checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0);
@@ -79,219 +79,218 @@
expect(Int64.MAX_VALUE.isZero, false);
});
test("bitLength", () {
- expect(new Int64(-2).bitLength, 1);
+ expect(Int64(-2).bitLength, 1);
expect((-Int64.ONE).bitLength, 0);
expect(Int64.ZERO.bitLength, 0);
expect((Int64.ONE << 21).bitLength, 22);
expect((Int64.ONE << 22).bitLength, 23);
expect((Int64.ONE << 43).bitLength, 44);
expect((Int64.ONE << 44).bitLength, 45);
- expect(new Int64(2).bitLength, 2);
+ expect(Int64(2).bitLength, 2);
expect(Int64.MAX_VALUE.bitLength, 63);
expect(Int64.MIN_VALUE.bitLength, 63);
});
});
group("arithmetic operators", () {
- Int64 n1 = new Int64(1234);
- Int64 n2 = new Int64(9876);
- Int64 n3 = new Int64(-1234);
- Int64 n4 = new Int64(-9876);
- Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd);
- Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444);
+ Int64 n1 = Int64(1234);
+ Int64 n2 = Int64(9876);
+ Int64 n3 = Int64(-1234);
+ Int64 n4 = Int64(-9876);
+ Int64 n5 = Int64.fromInts(0x12345678, 0xabcdabcd);
+ Int64 n6 = Int64.fromInts(0x77773333, 0x22224444);
test("+", () {
- expect(n1 + n2, new Int64(11110));
- expect(n3 + n2, new Int64(8642));
- expect(n3 + n4, new Int64(-11110));
- expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011));
+ 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);
});
test("-", () {
- expect(n1 - n2, new Int64(-8642));
- expect(n3 - n2, new Int64(-11110));
- expect(n3 - n4, new Int64(8642));
- expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789));
+ 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);
});
test("unary -", () {
- expect(-n1, new Int64(-1234));
+ expect(-n1, Int64(-1234));
expect(-Int64.ZERO, Int64.ZERO);
});
test("*", () {
- expect(new Int64(1111) * new Int64(3), new Int64(3333));
- expect(new Int64(1111) * new Int64(-3), new Int64(-3333));
- expect(new Int64(-1111) * new Int64(3), new Int64(-3333));
- expect(new Int64(-1111) * new Int64(-3), new Int64(3333));
- expect(new Int64(100) * Int64.ZERO, Int64.ZERO);
+ expect(Int64(1111) * Int64(3), Int64(3333));
+ expect(Int64(1111) * Int64(-3), Int64(-3333));
+ expect(Int64(-1111) * Int64(3), Int64(-3333));
+ expect(Int64(-1111) * Int64(-3), Int64(3333));
+ expect(Int64(100) * Int64.ZERO, Int64.ZERO);
expect(
- new Int64.fromInts(0x12345678, 0x12345678) *
- new Int64.fromInts(0x1234, 0x12345678),
- new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
+ Int64.fromInts(0x12345678, 0x12345678) *
+ Int64.fromInts(0x1234, 0x12345678),
+ Int64.fromInts(0x7ff63f7c, 0x1df4d840));
expect(
- new Int64.fromInts(0xf2345678, 0x12345678) *
- new Int64.fromInts(0x1234, 0x12345678),
- new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
+ Int64.fromInts(0xf2345678, 0x12345678) *
+ Int64.fromInts(0x1234, 0x12345678),
+ Int64.fromInts(0x7ff63f7c, 0x1df4d840));
expect(
- new Int64.fromInts(0xf2345678, 0x12345678) *
- new Int64.fromInts(0xffff1234, 0x12345678),
- new Int64.fromInts(0x297e3f7c, 0x1df4d840));
+ Int64.fromInts(0xf2345678, 0x12345678) *
+ Int64.fromInts(0xffff1234, 0x12345678),
+ Int64.fromInts(0x297e3f7c, 0x1df4d840));
// RHS Int32
- expect((new Int64(123456789) * new Int32(987654321)),
- new Int64.fromInts(0x1b13114, 0xfbff5385));
- expect((new Int64(123456789) * new Int32(987654321)),
- new Int64.fromInts(0x1b13114, 0xfbff5385));
+ expect((Int64(123456789) * Int32(987654321)),
+ Int64.fromInts(0x1b13114, 0xfbff5385));
+ expect((Int64(123456789) * Int32(987654321)),
+ Int64.fromInts(0x1b13114, 0xfbff5385));
// Wraparound
- expect((new Int64(123456789) * new Int64(987654321)),
- new Int64.fromInts(0x1b13114, 0xfbff5385));
+ expect((Int64(123456789) * Int64(987654321)),
+ Int64.fromInts(0x1b13114, 0xfbff5385));
- expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO);
- expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE);
- expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE);
+ 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);
});
test("~/", () {
- Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF);
- Int64 ten = new Int64(10);
+ Int64 deadBeef = Int64.fromInts(0xDEADBEEF, 0xDEADBEEF);
+ Int64 ten = Int64(10);
- expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5));
+ expect(deadBeef ~/ ten, Int64.fromInts(0xfcaaf97e, 0x63115fe5));
expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO);
- expect(Int64.MAX_VALUE ~/ Int64.TWO,
- new Int64.fromInts(0x3fffffff, 0xffffffff));
- expect(Int64.ZERO ~/ new Int64(1000), Int64.ZERO);
+ expect(
+ Int64.MAX_VALUE ~/ Int64.TWO, Int64.fromInts(0x3fffffff, 0xffffffff));
+ expect(Int64.ZERO ~/ Int64(1000), Int64.ZERO);
expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE);
- expect(new Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO);
- expect(Int64.MIN_VALUE ~/ new Int64(8192), new Int64(-1125899906842624));
- expect(Int64.MIN_VALUE ~/ new Int64(8193), new Int64(-1125762484664320));
- expect(new Int64(-1000) ~/ new Int64(8192), Int64.ZERO);
- expect(new Int64(-1000) ~/ new Int64(8193), Int64.ZERO);
- expect(new Int64(-1000000000) ~/ new Int64(8192), new Int64(-122070));
- expect(new Int64(-1000000000) ~/ new Int64(8193), new Int64(-122055));
- expect(new Int64(1000000000) ~/ new Int64(8192), new Int64(122070));
- expect(new Int64(1000000000) ~/ new Int64(8193), new Int64(122055));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400),
- new Int64.fromInts(0x1fffff, 0xffffffff));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000),
- new Int64.fromInts(0x1fff, 0xffffffff));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000),
- new Int64.fromInts(0x1f, 0xffffffff));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000),
- new Int64(536870911));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000),
- new Int64(2097151));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000),
- new Int64(8191));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000),
- new Int64(31));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300),
- new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000),
- new Int64.fromInts(0x2, 0xAAAAAAAA));
- expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000),
- new Int64(0x2AA));
- expect(Int64.MAX_VALUE ~/ new Int64(0x123456),
- new Int64.fromInts(0x708, 0x002E9501));
- expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9));
- expect(new Int64(5) ~/ new Int64(5), Int64.ONE);
- expect(new Int64(1000) ~/ new Int64(3), new Int64(333));
- expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333));
- expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333));
- expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333));
- expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO);
+ expect(Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO);
+ expect(Int64.MIN_VALUE ~/ Int64(8192), Int64(-1125899906842624));
+ expect(Int64.MIN_VALUE ~/ Int64(8193), Int64(-1125762484664320));
+ expect(Int64(-1000) ~/ Int64(8192), Int64.ZERO);
+ expect(Int64(-1000) ~/ Int64(8193), Int64.ZERO);
+ expect(Int64(-1000000000) ~/ Int64(8192), Int64(-122070));
+ expect(Int64(-1000000000) ~/ Int64(8193), Int64(-122055));
+ expect(Int64(1000000000) ~/ Int64(8192), Int64(122070));
+ expect(Int64(1000000000) ~/ Int64(8193), Int64(122055));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00000400),
+ Int64.fromInts(0x1fffff, 0xffffffff));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00040000),
+ Int64.fromInts(0x1fff, 0xffffffff));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x04000000),
+ Int64.fromInts(0x1f, 0xffffffff));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000004, 0x00000000),
+ Int64(536870911));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000400, 0x00000000),
+ Int64(2097151));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00040000, 0x00000000),
+ Int64(8191));
expect(
- new Int64.fromInts(0x12345678, 0x12345678) ~/
- new Int64.fromInts(0x0, 0x123),
- new Int64.fromInts(0x1003d0, 0xe84f5ae8));
+ Int64.MAX_VALUE ~/ Int64.fromInts(0x04000000, 0x00000000), Int64(31));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x00000300),
+ Int64.fromInts(0x2AAAAA, 0xAAAAAAAA));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00000000, 0x30000000),
+ Int64.fromInts(0x2, 0xAAAAAAAA));
+ expect(Int64.MAX_VALUE ~/ Int64.fromInts(0x00300000, 0x00000000),
+ Int64(0x2AA));
+ expect(Int64.MAX_VALUE ~/ Int64(0x123456),
+ Int64.fromInts(0x708, 0x002E9501));
+ expect(Int64.MAX_VALUE % Int64(0x123456), Int64(0x3BDA9));
+ expect(Int64(5) ~/ Int64(5), Int64.ONE);
+ expect(Int64(1000) ~/ Int64(3), Int64(333));
+ expect(Int64(1000) ~/ Int64(-3), Int64(-333));
+ expect(Int64(-1000) ~/ Int64(3), Int64(-333));
+ expect(Int64(-1000) ~/ Int64(-3), Int64(333));
+ expect(Int64(3) ~/ Int64(1000), Int64.ZERO);
expect(
- new Int64.fromInts(0x12345678, 0x12345678) ~/
- new Int64.fromInts(0x1234, 0x12345678),
- new Int64.fromInts(0x0, 0x10003));
+ Int64.fromInts(0x12345678, 0x12345678) ~/ Int64.fromInts(0x0, 0x123),
+ Int64.fromInts(0x1003d0, 0xe84f5ae8));
expect(
- new Int64.fromInts(0xf2345678, 0x12345678) ~/
- new Int64.fromInts(0x1234, 0x12345678),
- new Int64.fromInts(0xffffffff, 0xffff3dfe));
+ Int64.fromInts(0x12345678, 0x12345678) ~/
+ Int64.fromInts(0x1234, 0x12345678),
+ Int64.fromInts(0x0, 0x10003));
expect(
- new Int64.fromInts(0xf2345678, 0x12345678) ~/
- new Int64.fromInts(0xffff1234, 0x12345678),
- new Int64.fromInts(0x0, 0xeda));
- expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461));
- expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461));
- expect(new Int64(829893893) ~/ 1919, new Int32(432461));
- expect(() => new Int64(1) ~/ Int64.ZERO,
- throwsA(new TypeMatcher<IntegerDivisionByZeroException>()));
- expect(Int64.MIN_VALUE ~/ new Int64(2),
- new Int64.fromInts(0xc0000000, 0x00000000));
- expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE);
- expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE);
- expect(() => new Int64(17) ~/ Int64.ZERO,
- throwsA(new TypeMatcher<IntegerDivisionByZeroException>()));
+ Int64.fromInts(0xf2345678, 0x12345678) ~/
+ Int64.fromInts(0x1234, 0x12345678),
+ Int64.fromInts(0xffffffff, 0xffff3dfe));
+ expect(
+ Int64.fromInts(0xf2345678, 0x12345678) ~/
+ Int64.fromInts(0xffff1234, 0x12345678),
+ Int64.fromInts(0x0, 0xeda));
+ expect(Int64(829893893) ~/ Int32(1919), Int32(432461));
+ expect(Int64(829893893) ~/ Int64(1919), Int32(432461));
+ expect(Int64(829893893) ~/ 1919, Int32(432461));
+ expect(() => Int64(1) ~/ Int64.ZERO,
+ throwsA(const TypeMatcher<IntegerDivisionByZeroException>()));
+ expect(
+ Int64.MIN_VALUE ~/ Int64(2), Int64.fromInts(0xc0000000, 0x00000000));
+ expect(Int64.MIN_VALUE ~/ Int64(1), Int64.MIN_VALUE);
+ expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE);
+ expect(() => Int64(17) ~/ Int64.ZERO,
+ throwsA(const TypeMatcher<IntegerDivisionByZeroException>()));
argumentErrorTest("~/", (a, b) => a ~/ b);
});
test("%", () {
// Define % as Euclidean mod, with positive result for all arguments
- expect(Int64.ZERO % new Int64(1000), Int64.ZERO);
+ expect(Int64.ZERO % Int64(1000), Int64.ZERO);
expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO);
- expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000));
- expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO);
- expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145));
- expect(new Int64(-1000) % new Int64(8192), new Int64(7192));
- expect(new Int64(-1000) % new Int64(8193), new Int64(7193));
- expect(new Int64(-1000000000) % new Int64(8192), new Int64(5632));
- expect(new Int64(-1000000000) % new Int64(8193), new Int64(4808));
- expect(new Int64(1000000000) % new Int64(8192), new Int64(2560));
- expect(new Int64(1000000000) % new Int64(8193), new Int64(3385));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400),
- new Int64.fromInts(0x0, 0x3ff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000),
- new Int64.fromInts(0x0, 0x3ffff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000),
- new Int64.fromInts(0x0, 0x3ffffff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000),
- new Int64.fromInts(0x3, 0xffffffff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000),
- new Int64.fromInts(0x3ff, 0xffffffff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000),
- new Int64.fromInts(0x3ffff, 0xffffffff));
- expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000),
- new Int64.fromInts(0x3ffffff, 0xffffffff));
- expect(new Int64(0x12345678).remainder(new Int64(0x22)),
- new Int64(0x12345678.remainder(0x22)));
- expect(new Int64(0x12345678).remainder(new Int64(-0x22)),
- new Int64(0x12345678.remainder(-0x22)));
- expect(new Int64(-0x12345678).remainder(new Int64(-0x22)),
- new Int64(-0x12345678.remainder(-0x22)));
- expect(new Int64(-0x12345678).remainder(new Int64(0x22)),
- new Int64(-0x12345678.remainder(0x22)));
- expect(new Int32(0x12345678).remainder(new Int64(0x22)),
- new Int64(0x12345678.remainder(0x22)));
+ expect(Int64(1000) % Int64.MIN_VALUE, Int64(1000));
+ expect(Int64.MIN_VALUE % Int64(8192), Int64.ZERO);
+ expect(Int64.MIN_VALUE % Int64(8193), Int64(6145));
+ expect(Int64(-1000) % Int64(8192), Int64(7192));
+ expect(Int64(-1000) % Int64(8193), Int64(7193));
+ expect(Int64(-1000000000) % Int64(8192), Int64(5632));
+ expect(Int64(-1000000000) % Int64(8193), Int64(4808));
+ expect(Int64(1000000000) % Int64(8192), Int64(2560));
+ expect(Int64(1000000000) % Int64(8193), Int64(3385));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x00000400),
+ Int64.fromInts(0x0, 0x3ff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x00040000),
+ Int64.fromInts(0x0, 0x3ffff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00000000, 0x04000000),
+ Int64.fromInts(0x0, 0x3ffffff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00000004, 0x00000000),
+ Int64.fromInts(0x3, 0xffffffff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00000400, 0x00000000),
+ Int64.fromInts(0x3ff, 0xffffffff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x00040000, 0x00000000),
+ Int64.fromInts(0x3ffff, 0xffffffff));
+ expect(Int64.MAX_VALUE % Int64.fromInts(0x04000000, 0x00000000),
+ Int64.fromInts(0x3ffffff, 0xffffffff));
+ expect(Int64(0x12345678).remainder(Int64(0x22)),
+ Int64(0x12345678.remainder(0x22)));
+ expect(Int64(0x12345678).remainder(Int64(-0x22)),
+ Int64(0x12345678.remainder(-0x22)));
+ expect(Int64(-0x12345678).remainder(Int64(-0x22)),
+ Int64(-0x12345678.remainder(-0x22)));
+ expect(Int64(-0x12345678).remainder(Int64(0x22)),
+ Int64(-0x12345678.remainder(0x22)));
+ expect(Int32(0x12345678).remainder(Int64(0x22)),
+ Int64(0x12345678.remainder(0x22)));
argumentErrorTest("%", (a, b) => a % b);
});
test("clamp", () {
- Int64 val = new Int64(17);
- expect(val.clamp(20, 30), new Int64(20));
- expect(val.clamp(10, 20), new Int64(17));
- expect(val.clamp(10, 15), new Int64(15));
+ Int64 val = Int64(17);
+ expect(val.clamp(20, 30), Int64(20));
+ expect(val.clamp(10, 20), Int64(17));
+ expect(val.clamp(10, 15), Int64(15));
- expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20));
- expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17));
- expect(val.clamp(new Int32(10), new Int32(15)), new Int64(15));
+ expect(val.clamp(Int32(20), Int32(30)), Int64(20));
+ expect(val.clamp(Int32(10), Int32(20)), Int64(17));
+ expect(val.clamp(Int32(10), Int32(15)), Int64(15));
- expect(val.clamp(new Int64(20), new Int64(30)), new Int64(20));
- expect(val.clamp(new Int64(10), new Int64(20)), new Int64(17));
- expect(val.clamp(new Int64(10), new Int64(15)), new Int64(15));
- expect(val.clamp(Int64.MIN_VALUE, new Int64(30)), new Int64(17));
- expect(val.clamp(new Int64(10), Int64.MAX_VALUE), new Int64(17));
+ expect(val.clamp(Int64(20), Int64(30)), Int64(20));
+ expect(val.clamp(Int64(10), Int64(20)), Int64(17));
+ expect(val.clamp(Int64(10), Int64(15)), Int64(15));
+ expect(val.clamp(Int64.MIN_VALUE, Int64(30)), Int64(17));
+ expect(val.clamp(Int64(10), Int64.MAX_VALUE), Int64(17));
expect(() => val.clamp(1, 'b'), throwsA(isArgumentError));
expect(() => val.clamp('a', 1), throwsA(isArgumentError));
@@ -304,14 +303,14 @@
expect(value.numberOfLeadingZeros(), zeros);
}
- checkZeros(new Int64(0), 64);
- checkZeros(new Int64(1), 63);
- checkZeros(new Int64.fromInts(0x00000000, 0x003fffff), 42);
- checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 41);
- checkZeros(new Int64.fromInts(0x00000fff, 0xffffffff), 20);
- checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 19);
- checkZeros(new Int64.fromInts(0x7fffffff, 0xffffffff), 1);
- checkZeros(new Int64(-1), 0);
+ checkZeros(Int64(0), 64);
+ checkZeros(Int64(1), 63);
+ checkZeros(Int64.fromInts(0x00000000, 0x003fffff), 42);
+ checkZeros(Int64.fromInts(0x00000000, 0x00400000), 41);
+ checkZeros(Int64.fromInts(0x00000fff, 0xffffffff), 20);
+ checkZeros(Int64.fromInts(0x00001000, 0x00000000), 19);
+ checkZeros(Int64.fromInts(0x7fffffff, 0xffffffff), 1);
+ checkZeros(Int64(-1), 0);
});
test("numberOfTrailingZeros", () {
@@ -319,31 +318,31 @@
expect(value.numberOfTrailingZeros(), zeros);
}
- checkZeros(new Int64(-1), 0);
- checkZeros(new Int64(1), 0);
- checkZeros(new Int64(2), 1);
- checkZeros(new Int64.fromInts(0x00000000, 0x00200000), 21);
- checkZeros(new Int64.fromInts(0x00000000, 0x00400000), 22);
- checkZeros(new Int64.fromInts(0x00000800, 0x00000000), 43);
- checkZeros(new Int64.fromInts(0x00001000, 0x00000000), 44);
- checkZeros(new Int64.fromInts(0x80000000, 0x00000000), 63);
- checkZeros(new Int64(0), 64);
+ checkZeros(Int64(-1), 0);
+ checkZeros(Int64(1), 0);
+ checkZeros(Int64(2), 1);
+ checkZeros(Int64.fromInts(0x00000000, 0x00200000), 21);
+ checkZeros(Int64.fromInts(0x00000000, 0x00400000), 22);
+ checkZeros(Int64.fromInts(0x00000800, 0x00000000), 43);
+ checkZeros(Int64.fromInts(0x00001000, 0x00000000), 44);
+ checkZeros(Int64.fromInts(0x80000000, 0x00000000), 63);
+ checkZeros(Int64(0), 64);
});
});
group("comparison operators", () {
- Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0);
- Int64 largePos = new Int64.fromInts(0x12341234, 0x0);
- Int64 largePosPlusOne = largePos + new Int64(1);
+ Int64 largeNeg = Int64.fromInts(0x82341234, 0x0);
+ Int64 largePos = Int64.fromInts(0x12341234, 0x0);
+ Int64 largePosPlusOne = largePos + Int64(1);
test("<", () {
- expect(new Int64(10) < new Int64(11), true);
- expect(new Int64(10) < new Int64(10), false);
- expect(new Int64(10) < new Int64(9), false);
- expect(new Int64(10) < new Int32(11), true);
- expect(new Int64(10) < new Int32(10), false);
- expect(new Int64(10) < new Int32(9), false);
- expect(new Int64(-10) < new Int64(-11), false);
+ expect(Int64(10) < Int64(11), true);
+ expect(Int64(10) < Int64(10), false);
+ expect(Int64(10) < Int64(9), false);
+ expect(Int64(10) < Int32(11), true);
+ expect(Int64(10) < Int32(10), false);
+ expect(Int64(10) < Int32(9), false);
+ expect(Int64(-10) < Int64(-11), false);
expect(Int64.MIN_VALUE < Int64.ZERO, true);
expect(largeNeg < largePos, true);
expect(largePos < largePosPlusOne, true);
@@ -355,14 +354,14 @@
});
test("<=", () {
- expect(new Int64(10) <= new Int64(11), true);
- expect(new Int64(10) <= new Int64(10), true);
- expect(new Int64(10) <= new Int64(9), false);
- expect(new Int64(10) <= new Int32(11), true);
- expect(new Int64(10) <= new Int32(10), true);
- expect(new Int64(10) <= new Int64(9), false);
- expect(new Int64(-10) <= new Int64(-11), false);
- expect(new Int64(-10) <= new Int64(-10), true);
+ expect(Int64(10) <= Int64(11), true);
+ expect(Int64(10) <= Int64(10), true);
+ expect(Int64(10) <= Int64(9), false);
+ expect(Int64(10) <= Int32(11), true);
+ expect(Int64(10) <= Int32(10), true);
+ expect(Int64(10) <= Int64(9), false);
+ expect(Int64(-10) <= Int64(-11), false);
+ expect(Int64(-10) <= Int64(-10), true);
expect(largeNeg <= largePos, true);
expect(largePos <= largeNeg, false);
expect(largePos <= largePosPlusOne, true);
@@ -374,42 +373,42 @@
});
test("==", () {
- expect(new Int64(0) == new Int64(0), true);
- expect(new Int64(0) == new Int64(1), false);
- expect(new Int64(0) == new Int32(0), true);
- expect(new Int64(0) == new Int32(1), false);
- expect(new Int64(0) == 0, true);
- expect(new Int64(0) == 1, false);
- expect(new Int64(10) == new Int64(11), false);
- expect(new Int64(10) == new Int64(10), true);
- expect(new Int64(10) == new Int64(9), false);
- expect(new Int64(10) == new Int32(11), false);
- expect(new Int64(10) == new Int32(10), true);
- expect(new Int64(10) == new Int32(9), false);
- expect(new Int64(10) == 11, false);
- expect(new Int64(10) == 10, true);
- expect(new Int64(10) == 9, false);
- expect(new Int64(-10) == new Int64(-10), true);
- expect(new Int64(-10) != new Int64(-10), false);
- expect(new Int64(-10) == -10, true);
- expect(new Int64(-10) == -9, false);
+ expect(Int64(0) == Int64(0), true);
+ expect(Int64(0) == Int64(1), false);
+ expect(Int64(0) == Int32(0), true);
+ expect(Int64(0) == Int32(1), false);
+ expect(Int64(0) == 0, true);
+ expect(Int64(0) == 1, false);
+ expect(Int64(10) == Int64(11), false);
+ expect(Int64(10) == Int64(10), true);
+ expect(Int64(10) == Int64(9), false);
+ expect(Int64(10) == Int32(11), false);
+ expect(Int64(10) == Int32(10), true);
+ expect(Int64(10) == Int32(9), false);
+ expect(Int64(10) == 11, false);
+ expect(Int64(10) == 10, true);
+ expect(Int64(10) == 9, false);
+ expect(Int64(-10) == Int64(-10), true);
+ expect(Int64(-10) != Int64(-10), false);
+ expect(Int64(-10) == -10, true);
+ expect(Int64(-10) == -9, false);
expect(largePos == largePos, true);
expect(largePos == largePosPlusOne, false);
expect(largePosPlusOne == largePos, false);
expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false);
- expect(new Int64(17) == new Object(), false);
- expect(new Int64(17) == null, false);
+ expect(Int64(17) == Object(), false);
+ expect(Int64(17) == null, false);
});
test(">=", () {
- expect(new Int64(10) >= new Int64(11), false);
- expect(new Int64(10) >= new Int64(10), true);
- expect(new Int64(10) >= new Int64(9), true);
- expect(new Int64(10) >= new Int32(11), false);
- expect(new Int64(10) >= new Int32(10), true);
- expect(new Int64(10) >= new Int32(9), true);
- expect(new Int64(-10) >= new Int64(-11), true);
- expect(new Int64(-10) >= new Int64(-10), true);
+ expect(Int64(10) >= Int64(11), false);
+ expect(Int64(10) >= Int64(10), true);
+ expect(Int64(10) >= Int64(9), true);
+ expect(Int64(10) >= Int32(11), false);
+ expect(Int64(10) >= Int32(10), true);
+ expect(Int64(10) >= Int32(9), true);
+ expect(Int64(-10) >= Int64(-11), true);
+ expect(Int64(-10) >= Int64(-10), true);
expect(largePos >= largeNeg, true);
expect(largeNeg >= largePos, false);
expect(largePos >= largePosPlusOne, false);
@@ -421,15 +420,15 @@
});
test(">", () {
- expect(new Int64(10) > new Int64(11), false);
- expect(new Int64(10) > new Int64(10), false);
- expect(new Int64(10) > new Int64(9), true);
- expect(new Int64(10) > new Int32(11), false);
- expect(new Int64(10) > new Int32(10), false);
- expect(new Int64(10) > new Int32(9), true);
- expect(new Int64(-10) > new Int64(-11), true);
- expect(new Int64(10) > new Int64(-11), true);
- expect(new Int64(-10) > new Int64(11), false);
+ expect(Int64(10) > Int64(11), false);
+ expect(Int64(10) > Int64(10), false);
+ expect(Int64(10) > Int64(9), true);
+ expect(Int64(10) > Int32(11), false);
+ expect(Int64(10) > Int32(10), false);
+ expect(Int64(10) > Int32(9), true);
+ expect(Int64(-10) > Int64(-11), true);
+ expect(Int64(10) > Int64(-11), true);
+ expect(Int64(-10) > Int64(11), false);
expect(largePos > largeNeg, true);
expect(largeNeg > largePos, false);
expect(largePos > largePosPlusOne, false);
@@ -443,174 +442,171 @@
});
group("bitwise operators", () {
- Int64 n1 = new Int64(1234);
- Int64 n2 = new Int64(9876);
- Int64 n3 = new Int64(-1234);
- Int64 n4 = new Int64(0x1234) << 32;
- Int64 n5 = new Int64(0x9876) << 32;
+ Int64 n1 = Int64(1234);
+ Int64 n2 = Int64(9876);
+ Int64 n3 = Int64(-1234);
+ Int64 n4 = Int64(0x1234) << 32;
+ Int64 n5 = Int64(0x9876) << 32;
test("&", () {
- expect(n1 & n2, new Int64(1168));
- expect(n3 & n2, new Int64(8708));
- expect(n4 & n5, new Int64(0x1034) << 32);
+ 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);
});
test("|", () {
- expect(n1 | n2, new Int64(9942));
- expect(n3 | n2, new Int64(-66));
- expect(n4 | n5, new Int64(0x9a76) << 32);
+ 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);
});
test("^", () {
- expect(n1 ^ n2, new Int64(8774));
- expect(n3 ^ n2, new Int64(-8774));
- expect(n4 ^ n5, new Int64(0x8a42) << 32);
+ 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);
});
test("~", () {
- expect(-new Int64(1), new Int64(-1));
- expect(-new Int64(-1), new Int64(1));
+ expect(-Int64(1), Int64(-1));
+ expect(-Int64(-1), Int64(1));
expect(-Int64.MIN_VALUE, Int64.MIN_VALUE);
- expect(~n1, new Int64(-1235));
- expect(~n2, new Int64(-9877));
- expect(~n3, new Int64(1233));
- expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff));
- expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff));
+ expect(~n1, Int64(-1235));
+ expect(~n2, Int64(-9877));
+ expect(~n3, Int64(1233));
+ expect(~n4, Int64.fromInts(0xffffedcb, 0xffffffff));
+ expect(~n5, Int64.fromInts(0xffff6789, 0xffffffff));
});
});
group("bitshift operators", () {
test("<<", () {
- expect(new Int64.fromInts(0x12341234, 0x45674567) << 10,
- new Int64.fromInts(0xd048d115, 0x9d159c00));
- expect(new Int64.fromInts(0x92341234, 0x45674567) << 10,
- new Int64.fromInts(0xd048d115, 0x9d159c00));
- expect(new Int64(-1) << 5, new Int64(-32));
- expect(new Int64(-1) << 0, new Int64(-1));
- expect(new Int64(42) << 64, Int64.ZERO);
- expect(new Int64(42) << 65, Int64.ZERO);
- expect(() => new Int64(17) << -1, throwsArgumentError);
- expect(() => new Int64(17) << null, throwsNoSuchMethodError);
+ expect(Int64.fromInts(0x12341234, 0x45674567) << 10,
+ Int64.fromInts(0xd048d115, 0x9d159c00));
+ expect(Int64.fromInts(0x92341234, 0x45674567) << 10,
+ Int64.fromInts(0xd048d115, 0x9d159c00));
+ expect(Int64(-1) << 5, Int64(-32));
+ expect(Int64(-1) << 0, Int64(-1));
+ expect(Int64(42) << 64, Int64.ZERO);
+ expect(Int64(42) << 65, Int64.ZERO);
+ expect(() => Int64(17) << -1, throwsArgumentError);
+ expect(() => Int64(17) << null, throwsNoSuchMethodError);
});
test(">>", () {
expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624");
- expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10,
- new Int64.fromInts(0x48d04, 0x8d1159d1));
- expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10,
- new Int64.fromInts(0xffe48d04, 0x8d1159d1));
- expect(
- new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, new Int64(67108863));
- expect(new Int64(42) >> 64, Int64.ZERO);
- expect(new Int64(42) >> 65, Int64.ZERO);
+ expect(Int64.fromInts(0x12341234, 0x45674567) >> 10,
+ Int64.fromInts(0x48d04, 0x8d1159d1));
+ expect(Int64.fromInts(0x92341234, 0x45674567) >> 10,
+ Int64.fromInts(0xffe48d04, 0x8d1159d1));
+ expect(Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, Int64(67108863));
+ expect(Int64(42) >> 64, Int64.ZERO);
+ expect(Int64(42) >> 65, Int64.ZERO);
for (int n = 0; n <= 66; n++) {
- expect(new Int64(-1) >> n, new Int64(-1));
+ expect(Int64(-1) >> n, Int64(-1));
}
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8,
- new Int64.fromInts(0x00723456, 0x789abcde));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16,
- new Int64.fromInts(0x00007234, 0x56789abc));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24,
- new Int64.fromInts(0x00000072, 0x3456789a));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28,
- new Int64.fromInts(0x00000007, 0x23456789));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32,
- new Int64.fromInts(0x00000000, 0x72345678));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 36,
- new Int64.fromInts(0x00000000, 0x07234567));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 40,
- new Int64.fromInts(0x00000000, 0x00723456));
- expect(new Int64.fromInts(0x72345678, 0x9abcde00) >> 44,
- new Int64.fromInts(0x00000000, 0x00072345));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 48,
- new Int64.fromInts(0x00000000, 0x00007234));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 8,
- new Int64.fromInts(0xff923456, 0x789abcde));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 16,
- new Int64.fromInts(0xffff9234, 0x56789abc));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 24,
- new Int64.fromInts(0xffffff92, 0x3456789a));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 28,
- new Int64.fromInts(0xfffffff9, 0x23456789));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32,
- new Int64.fromInts(0xffffffff, 0x92345678));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36,
- new Int64.fromInts(0xffffffff, 0xf9234567));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40,
- new Int64.fromInts(0xffffffff, 0xff923456));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44,
- new Int64.fromInts(0xffffffff, 0xfff92345));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48,
- new Int64.fromInts(0xffffffff, 0xffff9234));
- expect(() => new Int64(17) >> -1, throwsArgumentError);
- expect(() => new Int64(17) >> null, throwsNoSuchMethodError);
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 8,
+ Int64.fromInts(0x00723456, 0x789abcde));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 16,
+ Int64.fromInts(0x00007234, 0x56789abc));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 24,
+ Int64.fromInts(0x00000072, 0x3456789a));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 28,
+ Int64.fromInts(0x00000007, 0x23456789));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 32,
+ Int64.fromInts(0x00000000, 0x72345678));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 36,
+ Int64.fromInts(0x00000000, 0x07234567));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 40,
+ Int64.fromInts(0x00000000, 0x00723456));
+ expect(Int64.fromInts(0x72345678, 0x9abcde00) >> 44,
+ Int64.fromInts(0x00000000, 0x00072345));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0) >> 48,
+ Int64.fromInts(0x00000000, 0x00007234));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 8,
+ Int64.fromInts(0xff923456, 0x789abcde));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 16,
+ Int64.fromInts(0xffff9234, 0x56789abc));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 24,
+ Int64.fromInts(0xffffff92, 0x3456789a));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 28,
+ Int64.fromInts(0xfffffff9, 0x23456789));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 32,
+ Int64.fromInts(0xffffffff, 0x92345678));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 36,
+ Int64.fromInts(0xffffffff, 0xf9234567));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 40,
+ Int64.fromInts(0xffffffff, 0xff923456));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 44,
+ Int64.fromInts(0xffffffff, 0xfff92345));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0) >> 48,
+ Int64.fromInts(0xffffffff, 0xffff9234));
+ expect(() => Int64(17) >> -1, throwsArgumentError);
+ expect(() => Int64(17) >> null, throwsNoSuchMethodError);
});
test("shiftRightUnsigned", () {
- expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10),
- new Int64.fromInts(0x48d04, 0x8d1159d1));
- expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10),
- new Int64.fromInts(0x248d04, 0x8d1159d1));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8),
- new Int64.fromInts(0x00723456, 0x789abcde));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16),
- new Int64.fromInts(0x00007234, 0x56789abc));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24),
- new Int64.fromInts(0x00000072, 0x3456789a));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28),
- new Int64.fromInts(0x00000007, 0x23456789));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32),
- new Int64.fromInts(0x00000000, 0x72345678));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36),
- new Int64.fromInts(0x00000000, 0x07234567));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40),
- new Int64.fromInts(0x00000000, 0x00723456));
- expect(new Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44),
- new Int64.fromInts(0x00000000, 0x00072345));
- expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48),
- new Int64.fromInts(0x00000000, 0x00007234));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8),
- new Int64.fromInts(0x00923456, 0x789abcde));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16),
- new Int64.fromInts(0x00009234, 0x56789abc));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24),
- new Int64.fromInts(0x00000092, 0x3456789a));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28),
- new Int64.fromInts(0x00000009, 0x23456789));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32),
- new Int64.fromInts(0x00000000, 0x92345678));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36),
- new Int64.fromInts(0x00000000, 0x09234567));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40),
- new Int64.fromInts(0x00000000, 0x00923456));
- expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44),
- new Int64.fromInts(0x00000000, 0x00092345));
- expect(new Int64.fromInts(0x00000000, 0x00009234),
- new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48));
- expect(new Int64(-1).shiftRightUnsigned(64), Int64.ZERO);
- expect(new Int64(1).shiftRightUnsigned(64), Int64.ZERO);
- expect(() => new Int64(17).shiftRightUnsigned(-1), throwsArgumentError);
- expect(() => new Int64(17).shiftRightUnsigned(null),
- throwsNoSuchMethodError);
+ expect(Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10),
+ Int64.fromInts(0x48d04, 0x8d1159d1));
+ expect(Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10),
+ Int64.fromInts(0x248d04, 0x8d1159d1));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8),
+ Int64.fromInts(0x00723456, 0x789abcde));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16),
+ Int64.fromInts(0x00007234, 0x56789abc));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(24),
+ Int64.fromInts(0x00000072, 0x3456789a));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(28),
+ Int64.fromInts(0x00000007, 0x23456789));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(32),
+ Int64.fromInts(0x00000000, 0x72345678));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(36),
+ Int64.fromInts(0x00000000, 0x07234567));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(40),
+ Int64.fromInts(0x00000000, 0x00723456));
+ expect(Int64.fromInts(0x72345678, 0x9abcde00).shiftRightUnsigned(44),
+ Int64.fromInts(0x00000000, 0x00072345));
+ expect(Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(48),
+ Int64.fromInts(0x00000000, 0x00007234));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(8),
+ Int64.fromInts(0x00923456, 0x789abcde));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(16),
+ Int64.fromInts(0x00009234, 0x56789abc));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(24),
+ Int64.fromInts(0x00000092, 0x3456789a));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(28),
+ Int64.fromInts(0x00000009, 0x23456789));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32),
+ Int64.fromInts(0x00000000, 0x92345678));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36),
+ Int64.fromInts(0x00000000, 0x09234567));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40),
+ Int64.fromInts(0x00000000, 0x00923456));
+ expect(Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44),
+ Int64.fromInts(0x00000000, 0x00092345));
+ expect(Int64.fromInts(0x00000000, 0x00009234),
+ Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48));
+ expect(Int64(-1).shiftRightUnsigned(64), Int64.ZERO);
+ expect(Int64(1).shiftRightUnsigned(64), Int64.ZERO);
+ expect(() => Int64(17).shiftRightUnsigned(-1), throwsArgumentError);
+ expect(() => Int64(17).shiftRightUnsigned(null), throwsNoSuchMethodError);
});
test("overflow", () {
- expect((new Int64(1) << 63) >> 1,
- -new Int64.fromInts(0x40000000, 0x00000000));
- expect((new Int64(-1) << 32) << 32, new Int64(0));
+ expect((Int64(1) << 63) >> 1, -Int64.fromInts(0x40000000, 0x00000000));
+ expect((Int64(-1) << 32) << 32, Int64(0));
expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE);
- expect(Int64.MIN_VALUE << 1, new Int64(0));
- expect((-new Int64.fromInts(8, 0)) >> 1,
- new Int64.fromInts(0xfffffffc, 0x00000000));
- expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1),
- new Int64.fromInts(0x7ffffffc, 0x0));
+ expect(Int64.MIN_VALUE << 1, Int64(0));
+ expect(
+ (-Int64.fromInts(8, 0)) >> 1, Int64.fromInts(0xfffffffc, 0x00000000));
+ expect((-Int64.fromInts(8, 0)).shiftRightUnsigned(1),
+ Int64.fromInts(0x7ffffffc, 0x0));
});
});
@@ -644,19 +640,17 @@
expect(() => Int64.ONE.toUnsigned(65), throwsRangeError);
});
test("toDouble", () {
- expect(new Int64(0).toDouble(), same(0.0));
- expect(new Int64(100).toDouble(), same(100.0));
- expect(new Int64(-100).toDouble(), same(-100.0));
- expect(new Int64(2147483647).toDouble(), same(2147483647.0));
- expect(new Int64(2147483648).toDouble(), same(2147483648.0));
- expect(new Int64(-2147483647).toDouble(), same(-2147483647.0));
- expect(new Int64(-2147483648).toDouble(), same(-2147483648.0));
- expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0));
- expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0));
- expect(
- new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0));
- expect(
- new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0));
+ expect(Int64(0).toDouble(), same(0.0));
+ expect(Int64(100).toDouble(), same(100.0));
+ expect(Int64(-100).toDouble(), same(-100.0));
+ expect(Int64(2147483647).toDouble(), same(2147483647.0));
+ expect(Int64(2147483648).toDouble(), same(2147483648.0));
+ expect(Int64(-2147483647).toDouble(), same(-2147483647.0));
+ expect(Int64(-2147483648).toDouble(), same(-2147483648.0));
+ expect(Int64(4503599627370495).toDouble(), same(4503599627370495.0));
+ 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),
@@ -678,40 +672,40 @@
});
test("toInt", () {
- expect(new Int64(0).toInt(), 0);
- expect(new Int64(100).toInt(), 100);
- expect(new Int64(-100).toInt(), -100);
- expect(new Int64(2147483647).toInt(), 2147483647);
- expect(new Int64(2147483648).toInt(), 2147483648);
- expect(new Int64(-2147483647).toInt(), -2147483647);
- expect(new Int64(-2147483648).toInt(), -2147483648);
- expect(new Int64(4503599627370495).toInt(), 4503599627370495);
- expect(new Int64(4503599627370496).toInt(), 4503599627370496);
- expect(new Int64(-4503599627370495).toInt(), -4503599627370495);
- expect(new Int64(-4503599627370496).toInt(), -4503599627370496);
+ expect(Int64(0).toInt(), 0);
+ expect(Int64(100).toInt(), 100);
+ expect(Int64(-100).toInt(), -100);
+ expect(Int64(2147483647).toInt(), 2147483647);
+ expect(Int64(2147483648).toInt(), 2147483648);
+ expect(Int64(-2147483647).toInt(), -2147483647);
+ expect(Int64(-2147483648).toInt(), -2147483648);
+ expect(Int64(4503599627370495).toInt(), 4503599627370495);
+ expect(Int64(4503599627370496).toInt(), 4503599627370496);
+ expect(Int64(-4503599627370495).toInt(), -4503599627370495);
+ expect(Int64(-4503599627370496).toInt(), -4503599627370496);
});
test("toInt32", () {
- expect(new Int64(0).toInt32(), new Int32(0));
- expect(new Int64(1).toInt32(), new Int32(1));
- expect(new Int64(-1).toInt32(), new Int32(-1));
- expect(new Int64(2147483647).toInt32(), new Int32(2147483647));
- expect(new Int64(2147483648).toInt32(), new Int32(-2147483648));
- expect(new Int64(2147483649).toInt32(), new Int32(-2147483647));
- expect(new Int64(2147483650).toInt32(), new Int32(-2147483646));
- expect(new Int64(-2147483648).toInt32(), new Int32(-2147483648));
- expect(new Int64(-2147483649).toInt32(), new Int32(2147483647));
- expect(new Int64(-2147483650).toInt32(), new Int32(2147483646));
- expect(new Int64(-2147483651).toInt32(), new Int32(2147483645));
+ expect(Int64(0).toInt32(), Int32(0));
+ expect(Int64(1).toInt32(), Int32(1));
+ expect(Int64(-1).toInt32(), Int32(-1));
+ expect(Int64(2147483647).toInt32(), Int32(2147483647));
+ expect(Int64(2147483648).toInt32(), Int32(-2147483648));
+ expect(Int64(2147483649).toInt32(), Int32(-2147483647));
+ expect(Int64(2147483650).toInt32(), Int32(-2147483646));
+ expect(Int64(-2147483648).toInt32(), Int32(-2147483648));
+ expect(Int64(-2147483649).toInt32(), Int32(2147483647));
+ expect(Int64(-2147483650).toInt32(), Int32(2147483646));
+ expect(Int64(-2147483651).toInt32(), Int32(2147483645));
});
test("toBytes", () {
- expect(new Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]);
- expect(new Int64.fromInts(0x08070605, 0x04030201).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]);
- expect(new Int64.fromInts(0x01020304, 0x05060708).toBytes(),
+ expect(Int64.fromInts(0x01020304, 0x05060708).toBytes(),
[8, 7, 6, 5, 4, 3, 2, 1]);
- expect(new Int64(-1).toBytes(),
+ expect(Int64(-1).toBytes(),
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
});
});
@@ -719,27 +713,27 @@
test("JavaScript 53-bit integer boundary", () {
Int64 _factorial(Int64 n) {
if (n.isZero) {
- return new Int64(1);
+ return Int64(1);
} else {
- return n * _factorial(n - new Int64(1));
+ return n * _factorial(n - Int64(1));
}
}
- Int64 fact18 = _factorial(new Int64(18));
- Int64 fact17 = _factorial(new Int64(17));
- expect(fact18 ~/ fact17, new Int64(18));
+ Int64 fact18 = _factorial(Int64(18));
+ Int64 fact17 = _factorial(Int64(17));
+ expect(fact18 ~/ fact17, Int64(18));
});
test("min, max values", () {
- expect(new Int64(1) << 63, Int64.MIN_VALUE);
- expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE);
+ expect(Int64(1) << 63, Int64.MIN_VALUE);
+ expect(-(Int64.MIN_VALUE + Int64(1)), Int64.MAX_VALUE);
});
test("", () {
check(int n) {
// Sign change should commute with conversion.
- expect(-new Int64(-n), new Int64(n));
- expect(new Int64(-n), -new Int64(n));
+ expect(-Int64(-n), Int64(n));
+ expect(Int64(-n), -Int64(n));
}
check(10);
@@ -750,7 +744,7 @@
group("parse", () {
test("parseRadix10", () {
checkInt(int x) {
- expect(Int64.parseRadix('$x', 10), new Int64(x));
+ expect(Int64.parseRadix('$x', 10), Int64(x));
}
checkInt(0);
@@ -773,7 +767,7 @@
test("parseHex", () {
checkHex(String hexStr, int h, int l) {
- expect(Int64.parseHex(hexStr), new Int64.fromInts(h, l));
+ expect(Int64.parseHex(hexStr), Int64.fromInts(h, l));
}
checkHex('0', 0, 0);
@@ -821,33 +815,32 @@
group("string representation", () {
test("toString", () {
- expect(new Int64(0).toString(), "0");
- expect(new Int64(1).toString(), "1");
- expect(new Int64(-1).toString(), "-1");
- expect(new Int64(-10).toString(), "-10");
+ 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 =
- (new Int64(1000000000) * new Int64(top)) + new Int64(bottom);
+ Int64 fullnum = (Int64(1000000000) * Int64(top)) + Int64(bottom);
expect(fullnum.toString(), "922337201967490662");
expect((-fullnum).toString(), "-922337201967490662");
- expect(new Int64(123456789).toString(), "123456789");
+ expect(Int64(123456789).toString(), "123456789");
});
test("toHexString", () {
- Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234);
+ Int64 deadbeef12341234 = Int64.fromInts(0xDEADBEEF, 0x12341234);
expect(Int64.ZERO.toHexString(), "0");
expect(deadbeef12341234.toHexString(), "DEADBEEF12341234");
- expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(),
+ expect(Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(),
"17678A7DEF01234");
- expect(new Int64(123456789).toHexString(), "75BCD15");
+ expect(Int64(123456789).toHexString(), "75BCD15");
});
test("toRadixString", () {
- expect(new Int64(123456789).toRadixString(5), "223101104124");
+ expect(Int64(123456789).toRadixString(5), "223101104124");
expect(Int64.MIN_VALUE.toRadixString(2),
"-1000000000000000000000000000000000000000000000000000000000000000");
expect(Int64.MIN_VALUE.toRadixString(3),
@@ -884,9 +877,9 @@
expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7");
expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807");
expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff");
- expect(() => new Int64(42).toRadixString(-1), throwsArgumentError);
- expect(() => new Int64(42).toRadixString(0), throwsArgumentError);
- expect(() => new Int64(42).toRadixString(37), throwsArgumentError);
+ expect(() => Int64(42).toRadixString(-1), throwsArgumentError);
+ expect(() => Int64(42).toRadixString(0), throwsArgumentError);
+ expect(() => Int64(42).toRadixString(37), throwsArgumentError);
});
test("toStringUnsigned", () {
diff --git a/test/int_64_vm_test.dart b/test/int_64_vm_test.dart
index 549d365..e5e1303 100644
--- a/test/int_64_vm_test.dart
+++ b/test/int_64_vm_test.dart
@@ -34,8 +34,8 @@
test("", () {
check(int n) {
// Sign change should commute with conversion.
- expect(-new Int64(-n), new Int64(n));
- expect(new Int64(-n), -new Int64(n));
+ expect(-Int64(-n), Int64(n));
+ expect(Int64(-n), -Int64(n));
}
check(10);