| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library int64test; | 5 library int64test; |
| 6 | 6 |
| 7 import 'package:fixnum/fixnum.dart'; | 7 import 'package:fixnum/fixnum.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 void main() { | 10 void main() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); | 28 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); |
| 29 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 1 ], 0, 1); | 29 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 1 ], 0, 1); |
| 30 checkBytes([ 8, 7, 6, 5, 4, 3, 2, 1 ], 0x08070605, 0x04030201); | 30 checkBytes([ 8, 7, 6, 5, 4, 3, 2, 1 ], 0x08070605, 0x04030201); |
| 31 checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe ], | 31 checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe ], |
| 32 0xffffffff, 0xfffffffe); | 32 0xffffffff, 0xfffffffe); |
| 33 checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], | 33 checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ], |
| 34 0xffffffff, 0xffffffff); | 34 0xffffffff, 0xffffffff); |
| 35 }); | 35 }); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 argumentErrorTest(name, op, [receiver = Int64.ONE]) { |
| 39 throwsArgumentErrorMentioning(substring) => |
| 40 throwsA((e) => e is ArgumentError && '$e'.contains(substring)); |
| 41 |
| 42 expect(() => op(receiver, null), throwsArgumentErrorMentioning('null')); |
| 43 expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"')); |
| 44 } |
| 45 |
| 38 group("is-tests", () { | 46 group("is-tests", () { |
| 39 test("isEven", () { | 47 test("isEven", () { |
| 40 expect((-Int64.ONE).isEven, false); | 48 expect((-Int64.ONE).isEven, false); |
| 41 expect(Int64.ZERO.isEven, true); | 49 expect(Int64.ZERO.isEven, true); |
| 42 expect(Int64.ONE.isEven, false); | 50 expect(Int64.ONE.isEven, false); |
| 43 expect(Int64.TWO.isEven, true); | 51 expect(Int64.TWO.isEven, true); |
| 44 }); | 52 }); |
| 45 test("isMaxValue", () { | 53 test("isMaxValue", () { |
| 46 expect(Int64.MIN_VALUE.isMaxValue, false); | 54 expect(Int64.MIN_VALUE.isMaxValue, false); |
| 47 expect(Int64.ZERO.isMaxValue, false); | 55 expect(Int64.ZERO.isMaxValue, false); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 Int64 n4 = new Int64(-9876); | 97 Int64 n4 = new Int64(-9876); |
| 90 Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); | 98 Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); |
| 91 Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); | 99 Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); |
| 92 | 100 |
| 93 test("+", () { | 101 test("+", () { |
| 94 expect(n1 + n2, new Int64(11110)); | 102 expect(n1 + n2, new Int64(11110)); |
| 95 expect(n3 + n2, new Int64(8642)); | 103 expect(n3 + n2, new Int64(8642)); |
| 96 expect(n3 + n4, new Int64(-11110)); | 104 expect(n3 + n4, new Int64(-11110)); |
| 97 expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); | 105 expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); |
| 98 expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); | 106 expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); |
| 107 argumentErrorTest("+", (a, b) => a + b); |
| 99 }); | 108 }); |
| 100 | 109 |
| 101 test("-", () { | 110 test("-", () { |
| 102 expect(n1 - n2, new Int64(-8642)); | 111 expect(n1 - n2, new Int64(-8642)); |
| 103 expect(n3 - n2, new Int64(-11110)); | 112 expect(n3 - n2, new Int64(-11110)); |
| 104 expect(n3 - n4, new Int64(8642)); | 113 expect(n3 - n4, new Int64(8642)); |
| 105 expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); | 114 expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); |
| 106 expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); | 115 expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); |
| 116 argumentErrorTest("-", (a, b) => a - b); |
| 107 }); | 117 }); |
| 108 | 118 |
| 109 test("unary -", () { | 119 test("unary -", () { |
| 110 expect(-n1, new Int64(-1234)); | 120 expect(-n1, new Int64(-1234)); |
| 111 expect(-Int64.ZERO, Int64.ZERO); | 121 expect(-Int64.ZERO, Int64.ZERO); |
| 112 }); | 122 }); |
| 113 | 123 |
| 114 test("*", () { | 124 test("*", () { |
| 115 expect(new Int64(1111) * new Int64(3), new Int64(3333)); | 125 expect(new Int64(1111) * new Int64(3), new Int64(3333)); |
| 116 expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); | 126 expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 134 expect((new Int64(123456789) * new Int32(987654321)), | 144 expect((new Int64(123456789) * new Int32(987654321)), |
| 135 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 145 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 136 | 146 |
| 137 // Wraparound | 147 // Wraparound |
| 138 expect((new Int64(123456789) * new Int64(987654321)), | 148 expect((new Int64(123456789) * new Int64(987654321)), |
| 139 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 149 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 140 | 150 |
| 141 expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); | 151 expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); |
| 142 expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); | 152 expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); |
| 143 expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); | 153 expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); |
| 154 argumentErrorTest("*", (a, b) => a * b); |
| 144 }); | 155 }); |
| 145 | 156 |
| 146 test("~/", () { | 157 test("~/", () { |
| 147 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); | 158 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); |
| 148 Int64 ten = new Int64(10); | 159 Int64 ten = new Int64(10); |
| 149 | 160 |
| 150 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); | 161 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); |
| 151 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); | 162 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); |
| 152 expect(Int64.MAX_VALUE ~/ Int64.TWO, | 163 expect(Int64.MAX_VALUE ~/ Int64.TWO, |
| 153 new Int64.fromInts(0x3fffffff, 0xffffffff)); | 164 new Int64.fromInts(0x3fffffff, 0xffffffff)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); | 217 expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); |
| 207 expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); | 218 expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); |
| 208 expect(new Int64(829893893) ~/ 1919, new Int32(432461)); | 219 expect(new Int64(829893893) ~/ 1919, new Int32(432461)); |
| 209 expect(() => new Int64(1) ~/ Int64.ZERO, | 220 expect(() => new Int64(1) ~/ Int64.ZERO, |
| 210 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); | 221 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); |
| 211 expect(Int64.MIN_VALUE ~/ new Int64(2), | 222 expect(Int64.MIN_VALUE ~/ new Int64(2), |
| 212 new Int64.fromInts(0xc0000000, 0x00000000)); | 223 new Int64.fromInts(0xc0000000, 0x00000000)); |
| 213 expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); | 224 expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); |
| 214 expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); | 225 expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); |
| 215 expect(() => new Int64(17) ~/ Int64.ZERO, throws); | 226 expect(() => new Int64(17) ~/ Int64.ZERO, throws); |
| 216 expect(() => new Int64(17) ~/ null, throwsArgumentError); | 227 argumentErrorTest("~/", (a, b) => a ~/ b); |
| 217 }); | 228 }); |
| 218 | 229 |
| 219 test("%", () { | 230 test("%", () { |
| 220 // Define % as Euclidean mod, with positive result for all arguments | 231 // Define % as Euclidean mod, with positive result for all arguments |
| 221 expect(Int64.ZERO % new Int64(1000), Int64.ZERO); | 232 expect(Int64.ZERO % new Int64(1000), Int64.ZERO); |
| 222 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); | 233 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); |
| 223 expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000)); | 234 expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000)); |
| 224 expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO); | 235 expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO); |
| 225 expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145)); | 236 expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145)); |
| 226 expect(new Int64(-1000) % new Int64(8192), new Int64(7192)); | 237 expect(new Int64(-1000) % new Int64(8192), new Int64(7192)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 246 expect(new Int64(0x12345678).remainder(new Int64(0x22)), | 257 expect(new Int64(0x12345678).remainder(new Int64(0x22)), |
| 247 new Int64(0x12345678.remainder(0x22))); | 258 new Int64(0x12345678.remainder(0x22))); |
| 248 expect(new Int64(0x12345678).remainder(new Int64(-0x22)), | 259 expect(new Int64(0x12345678).remainder(new Int64(-0x22)), |
| 249 new Int64(0x12345678.remainder(-0x22))); | 260 new Int64(0x12345678.remainder(-0x22))); |
| 250 expect(new Int64(-0x12345678).remainder(new Int64(-0x22)), | 261 expect(new Int64(-0x12345678).remainder(new Int64(-0x22)), |
| 251 new Int64(-0x12345678.remainder(-0x22))); | 262 new Int64(-0x12345678.remainder(-0x22))); |
| 252 expect(new Int64(-0x12345678).remainder(new Int64(0x22)), | 263 expect(new Int64(-0x12345678).remainder(new Int64(0x22)), |
| 253 new Int64(-0x12345678.remainder(0x22))); | 264 new Int64(-0x12345678.remainder(0x22))); |
| 254 expect(new Int32(0x12345678).remainder(new Int64(0x22)), | 265 expect(new Int32(0x12345678).remainder(new Int64(0x22)), |
| 255 new Int64(0x12345678.remainder(0x22))); | 266 new Int64(0x12345678.remainder(0x22))); |
| 267 argumentErrorTest("%", (a, b) => a % b); |
| 256 }); | 268 }); |
| 257 | 269 |
| 258 test("clamp", () { | 270 test("clamp", () { |
| 259 Int64 val = new Int64(17); | 271 Int64 val = new Int64(17); |
| 260 expect(val.clamp(20, 30), new Int64(20)); | 272 expect(val.clamp(20, 30), new Int64(20)); |
| 261 expect(val.clamp(10, 20), new Int64(17)); | 273 expect(val.clamp(10, 20), new Int64(17)); |
| 262 expect(val.clamp(10, 15), new Int64(15)); | 274 expect(val.clamp(10, 15), new Int64(15)); |
| 263 | 275 |
| 264 expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20)); | 276 expect(val.clamp(new Int32(20), new Int32(30)), new Int64(20)); |
| 265 expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17)); | 277 expect(val.clamp(new Int32(10), new Int32(20)), new Int64(17)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 expect(new Int64(10) < new Int32(10), false); | 332 expect(new Int64(10) < new Int32(10), false); |
| 321 expect(new Int64(10) < new Int32(9), false); | 333 expect(new Int64(10) < new Int32(9), false); |
| 322 expect(new Int64(-10) < new Int64(-11), false); | 334 expect(new Int64(-10) < new Int64(-11), false); |
| 323 expect(Int64.MIN_VALUE < Int64.ZERO, true); | 335 expect(Int64.MIN_VALUE < Int64.ZERO, true); |
| 324 expect(largeNeg < largePos, true); | 336 expect(largeNeg < largePos, true); |
| 325 expect(largePos < largePosPlusOne, true); | 337 expect(largePos < largePosPlusOne, true); |
| 326 expect(largePos < largePos, false); | 338 expect(largePos < largePos, false); |
| 327 expect(largePosPlusOne < largePos, false); | 339 expect(largePosPlusOne < largePos, false); |
| 328 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); | 340 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); |
| 329 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); | 341 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); |
| 330 expect(() => new Int64(17) < null, throwsArgumentError); | 342 argumentErrorTest("<", (a, b) => a < b); |
| 331 }); | 343 }); |
| 332 | 344 |
| 333 test("<=", () { | 345 test("<=", () { |
| 334 expect(new Int64(10) <= new Int64(11), true); | 346 expect(new Int64(10) <= new Int64(11), true); |
| 335 expect(new Int64(10) <= new Int64(10), true); | 347 expect(new Int64(10) <= new Int64(10), true); |
| 336 expect(new Int64(10) <= new Int64(9), false); | 348 expect(new Int64(10) <= new Int64(9), false); |
| 337 expect(new Int64(10) <= new Int32(11), true); | 349 expect(new Int64(10) <= new Int32(11), true); |
| 338 expect(new Int64(10) <= new Int32(10), true); | 350 expect(new Int64(10) <= new Int32(10), true); |
| 339 expect(new Int64(10) <= new Int64(9), false); | 351 expect(new Int64(10) <= new Int64(9), false); |
| 340 expect(new Int64(-10) <= new Int64(-11), false); | 352 expect(new Int64(-10) <= new Int64(-11), false); |
| 341 expect(new Int64(-10) <= new Int64(-10), true); | 353 expect(new Int64(-10) <= new Int64(-10), true); |
| 342 expect(largeNeg <= largePos, true); | 354 expect(largeNeg <= largePos, true); |
| 343 expect(largePos <= largeNeg, false); | 355 expect(largePos <= largeNeg, false); |
| 344 expect(largePos <= largePosPlusOne, true); | 356 expect(largePos <= largePosPlusOne, true); |
| 345 expect(largePos <= largePos, true); | 357 expect(largePos <= largePos, true); |
| 346 expect(largePosPlusOne <= largePos, false); | 358 expect(largePosPlusOne <= largePos, false); |
| 347 expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); | 359 expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); |
| 348 expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); | 360 expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); |
| 349 expect(() => new Int64(17) <= null, throwsArgumentError); | 361 argumentErrorTest("<=", (a, b) => a <= b); |
| 350 }); | 362 }); |
| 351 | 363 |
| 352 test("==", () { | 364 test("==", () { |
| 353 expect(new Int64(0) == new Int64(0), true); | 365 expect(new Int64(0) == new Int64(0), true); |
| 354 expect(new Int64(0) == new Int64(1), false); | 366 expect(new Int64(0) == new Int64(1), false); |
| 355 expect(new Int64(0) == new Int32(0), true); | 367 expect(new Int64(0) == new Int32(0), true); |
| 356 expect(new Int64(0) == new Int32(1), false); | 368 expect(new Int64(0) == new Int32(1), false); |
| 357 expect(new Int64(0) == 0, true); | 369 expect(new Int64(0) == 0, true); |
| 358 expect(new Int64(0) == 1, false); | 370 expect(new Int64(0) == 1, false); |
| 359 expect(new Int64(10) == new Int64(11), false); | 371 expect(new Int64(10) == new Int64(11), false); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 386 expect(new Int64(10) >= new Int32(9), true); | 398 expect(new Int64(10) >= new Int32(9), true); |
| 387 expect(new Int64(-10) >= new Int64(-11), true); | 399 expect(new Int64(-10) >= new Int64(-11), true); |
| 388 expect(new Int64(-10) >= new Int64(-10), true); | 400 expect(new Int64(-10) >= new Int64(-10), true); |
| 389 expect(largePos >= largeNeg, true); | 401 expect(largePos >= largeNeg, true); |
| 390 expect(largeNeg >= largePos, false); | 402 expect(largeNeg >= largePos, false); |
| 391 expect(largePos >= largePosPlusOne, false); | 403 expect(largePos >= largePosPlusOne, false); |
| 392 expect(largePos >= largePos, true); | 404 expect(largePos >= largePos, true); |
| 393 expect(largePosPlusOne >= largePos, true); | 405 expect(largePosPlusOne >= largePos, true); |
| 394 expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); | 406 expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); |
| 395 expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); | 407 expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); |
| 396 expect(() => new Int64(17) >= null, throwsArgumentError); | 408 argumentErrorTest(">=", (a, b) => a >= b); |
| 397 }); | 409 }); |
| 398 | 410 |
| 399 test(">", () { | 411 test(">", () { |
| 400 expect(new Int64(10) > new Int64(11), false); | 412 expect(new Int64(10) > new Int64(11), false); |
| 401 expect(new Int64(10) > new Int64(10), false); | 413 expect(new Int64(10) > new Int64(10), false); |
| 402 expect(new Int64(10) > new Int64(9), true); | 414 expect(new Int64(10) > new Int64(9), true); |
| 403 expect(new Int64(10) > new Int32(11), false); | 415 expect(new Int64(10) > new Int32(11), false); |
| 404 expect(new Int64(10) > new Int32(10), false); | 416 expect(new Int64(10) > new Int32(10), false); |
| 405 expect(new Int64(10) > new Int32(9), true); | 417 expect(new Int64(10) > new Int32(9), true); |
| 406 expect(new Int64(-10) > new Int64(-11), true); | 418 expect(new Int64(-10) > new Int64(-11), true); |
| 407 expect(new Int64(10) > new Int64(-11), true); | 419 expect(new Int64(10) > new Int64(-11), true); |
| 408 expect(new Int64(-10) > new Int64(11), false); | 420 expect(new Int64(-10) > new Int64(11), false); |
| 409 expect(largePos > largeNeg, true); | 421 expect(largePos > largeNeg, true); |
| 410 expect(largeNeg > largePos, false); | 422 expect(largeNeg > largePos, false); |
| 411 expect(largePos > largePosPlusOne, false); | 423 expect(largePos > largePosPlusOne, false); |
| 412 expect(largePos > largePos, false); | 424 expect(largePos > largePos, false); |
| 413 expect(largePosPlusOne > largePos, true); | 425 expect(largePosPlusOne > largePos, true); |
| 414 expect(Int64.ZERO > Int64.MIN_VALUE, true); | 426 expect(Int64.ZERO > Int64.MIN_VALUE, true); |
| 415 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); | 427 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); |
| 416 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); | 428 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); |
| 417 expect(() => new Int64(17) > null, throwsArgumentError); | 429 argumentErrorTest(">", (a, b) => a > b); |
| 418 }); | 430 }); |
| 419 }); | 431 }); |
| 420 | 432 |
| 421 group("bitwise operators", () { | 433 group("bitwise operators", () { |
| 422 Int64 n1 = new Int64(1234); | 434 Int64 n1 = new Int64(1234); |
| 423 Int64 n2 = new Int64(9876); | 435 Int64 n2 = new Int64(9876); |
| 424 Int64 n3 = new Int64(-1234); | 436 Int64 n3 = new Int64(-1234); |
| 425 Int64 n4 = new Int64(0x1234) << 32; | 437 Int64 n4 = new Int64(0x1234) << 32; |
| 426 Int64 n5 = new Int64(0x9876) << 32; | 438 Int64 n5 = new Int64(0x9876) << 32; |
| 427 | 439 |
| 428 test("&", () { | 440 test("&", () { |
| 429 expect(n1 & n2, new Int64(1168)); | 441 expect(n1 & n2, new Int64(1168)); |
| 430 expect(n3 & n2, new Int64(8708)); | 442 expect(n3 & n2, new Int64(8708)); |
| 431 expect(n4 & n5, new Int64(0x1034) << 32); | 443 expect(n4 & n5, new Int64(0x1034) << 32); |
| 432 expect(() => n1 & null, throwsArgumentError); | 444 expect(() => n1 & null, throwsArgumentError); |
| 445 argumentErrorTest("&", (a, b) => a & b); |
| 433 }); | 446 }); |
| 434 | 447 |
| 435 test("|", () { | 448 test("|", () { |
| 436 expect(n1 | n2, new Int64(9942)); | 449 expect(n1 | n2, new Int64(9942)); |
| 437 expect(n3 | n2, new Int64(-66)); | 450 expect(n3 | n2, new Int64(-66)); |
| 438 expect(n4 | n5, new Int64(0x9a76) << 32); | 451 expect(n4 | n5, new Int64(0x9a76) << 32); |
| 439 expect(() => n1 | null, throwsArgumentError); | 452 expect(() => n1 | null, throwsArgumentError); |
| 453 argumentErrorTest("|", (a, b) => a | b); |
| 440 }); | 454 }); |
| 441 | 455 |
| 442 test("^", () { | 456 test("^", () { |
| 443 expect(n1 ^ n2, new Int64(8774)); | 457 expect(n1 ^ n2, new Int64(8774)); |
| 444 expect(n3 ^ n2, new Int64(-8774)); | 458 expect(n3 ^ n2, new Int64(-8774)); |
| 445 expect(n4 ^ n5, new Int64(0x8a42) << 32); | 459 expect(n4 ^ n5, new Int64(0x8a42) << 32); |
| 446 expect(() => n1 ^ null, throwsArgumentError); | 460 expect(() => n1 ^ null, throwsArgumentError); |
| 461 argumentErrorTest("^", (a, b) => a ^ b); |
| 447 }); | 462 }); |
| 448 | 463 |
| 449 test("~", () { | 464 test("~", () { |
| 450 expect(-new Int64(1), new Int64(-1)); | 465 expect(-new Int64(1), new Int64(-1)); |
| 451 expect(-new Int64(-1), new Int64(1)); | 466 expect(-new Int64(-1), new Int64(1)); |
| 452 expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); | 467 expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); |
| 453 | 468 |
| 454 expect(~n1, new Int64(-1235)); | 469 expect(~n1, new Int64(-1235)); |
| 455 expect(~n2, new Int64(-9877)); | 470 expect(~n2, new Int64(-9877)); |
| 456 expect(~n3, new Int64(1233)); | 471 expect(~n3, new Int64(1233)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44); | 600 expect((Int64.ONE << 44).toSigned(46), Int64.ONE << 44); |
| 586 expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44)); | 601 expect((Int64.ONE << 44).toSigned(45), -(Int64.ONE << 44)); |
| 587 expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22); | 602 expect((Int64.ONE << 22).toSigned(24), Int64.ONE << 22); |
| 588 expect((Int64.ONE << 22).toSigned(23), -(Int64.ONE << 22)); | 603 expect((Int64.ONE << 22).toSigned(23), -(Int64.ONE << 22)); |
| 589 expect(Int64.ONE.toSigned(2), Int64.ONE); | 604 expect(Int64.ONE.toSigned(2), Int64.ONE); |
| 590 expect(Int64.ONE.toSigned(1), -Int64.ONE); | 605 expect(Int64.ONE.toSigned(1), -Int64.ONE); |
| 591 expect(Int64.MAX_VALUE.toSigned(64), Int64.MAX_VALUE); | 606 expect(Int64.MAX_VALUE.toSigned(64), Int64.MAX_VALUE); |
| 592 expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE); | 607 expect(Int64.MIN_VALUE.toSigned(64), Int64.MIN_VALUE); |
| 593 expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE); | 608 expect(Int64.MAX_VALUE.toSigned(63), -Int64.ONE); |
| 594 expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO); | 609 expect(Int64.MIN_VALUE.toSigned(63), Int64.ZERO); |
| 595 expect(() => Int64.ONE.toSigned(0), throws); | 610 expect(() => Int64.ONE.toSigned(0), throwsRangeError); |
| 596 expect(() => Int64.ONE.toSigned(65), throws); | 611 expect(() => Int64.ONE.toSigned(65), throwsRangeError); |
| 597 }); | 612 }); |
| 598 test("toUnsigned", () { | 613 test("toUnsigned", () { |
| 599 expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); | 614 expect((Int64.ONE << 44).toUnsigned(45), Int64.ONE << 44); |
| 600 expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO); | 615 expect((Int64.ONE << 44).toUnsigned(44), Int64.ZERO); |
| 601 expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22); | 616 expect((Int64.ONE << 22).toUnsigned(23), Int64.ONE << 22); |
| 602 expect((Int64.ONE << 22).toUnsigned(22), Int64.ZERO); | 617 expect((Int64.ONE << 22).toUnsigned(22), Int64.ZERO); |
| 603 expect(Int64.ONE.toUnsigned(1), Int64.ONE); | 618 expect(Int64.ONE.toUnsigned(1), Int64.ONE); |
| 604 expect(Int64.ONE.toUnsigned(0), Int64.ZERO); | 619 expect(Int64.ONE.toUnsigned(0), Int64.ZERO); |
| 605 expect(Int64.MAX_VALUE.toUnsigned(64), Int64.MAX_VALUE); | 620 expect(Int64.MAX_VALUE.toUnsigned(64), Int64.MAX_VALUE); |
| 606 expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE); | 621 expect(Int64.MIN_VALUE.toUnsigned(64), Int64.MIN_VALUE); |
| 607 expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE); | 622 expect(Int64.MAX_VALUE.toUnsigned(63), Int64.MAX_VALUE); |
| 608 expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO); | 623 expect(Int64.MIN_VALUE.toUnsigned(63), Int64.ZERO); |
| 609 expect(() => Int64.ONE.toUnsigned(-1), throws); | 624 expect(() => Int64.ONE.toUnsigned(-1), throwsRangeError); |
| 610 expect(() => Int64.ONE.toUnsigned(65), throws); | 625 expect(() => Int64.ONE.toUnsigned(65), throwsRangeError); |
| 611 }); | 626 }); |
| 612 test("toDouble", () { | 627 test("toDouble", () { |
| 613 expect(new Int64(0).toDouble(), same(0.0)); | 628 expect(new Int64(0).toDouble(), same(0.0)); |
| 614 expect(new Int64(100).toDouble(), same(100.0)); | 629 expect(new Int64(100).toDouble(), same(100.0)); |
| 615 expect(new Int64(-100).toDouble(), same(-100.0)); | 630 expect(new Int64(-100).toDouble(), same(-100.0)); |
| 616 expect(new Int64(2147483647).toDouble(), same(2147483647.0)); | 631 expect(new Int64(2147483647).toDouble(), same(2147483647.0)); |
| 617 expect(new Int64(2147483648).toDouble(), same(2147483648.0)); | 632 expect(new Int64(2147483648).toDouble(), same(2147483648.0)); |
| 618 expect(new Int64(-2147483647).toDouble(), same(-2147483647.0)); | 633 expect(new Int64(-2147483647).toDouble(), same(-2147483647.0)); |
| 619 expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); | 634 expect(new Int64(-2147483648).toDouble(), same(-2147483648.0)); |
| 620 expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); | 635 expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0)); |
| 621 expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); | 636 expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0)); |
| 622 expect( | 637 expect(new Int64(-4503599627370495).toDouble(), |
| 623 new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0)); | 638 same(-4503599627370495.0)); |
| 624 expect( | 639 expect(new Int64(-4503599627370496).toDouble(), |
| 625 new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0)); | 640 same(-4503599627370496.0)); |
| 626 expect(Int64 | 641 expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1), |
| 627 .parseInt("-10000000000000000") | 642 "-10000000000000000.0"); |
| 628 .toDouble() | |
| 629 .toStringAsFixed(1), "-10000000000000000.0"); | |
| 630 expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), | 643 expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1), |
| 631 "-10000000000000000.0"); | 644 "-10000000000000000.0"); |
| 632 expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), | 645 expect(Int64.parseInt("-10000000000000002").toDouble().toStringAsFixed(1), |
| 633 "-10000000000000002.0"); | 646 "-10000000000000002.0"); |
| 634 expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1), | 647 expect(Int64.parseInt("-10000000000000003").toDouble().toStringAsFixed(1), |
| 635 "-10000000000000004.0"); | 648 "-10000000000000004.0"); |
| 636 expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1), | 649 expect(Int64.parseInt("-10000000000000004").toDouble().toStringAsFixed(1), |
| 637 "-10000000000000004.0"); | 650 "-10000000000000004.0"); |
| 638 expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1), | 651 expect(Int64.parseInt("-10000000000000005").toDouble().toStringAsFixed(1), |
| 639 "-10000000000000004.0"); | 652 "-10000000000000004.0"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 650 expect(new Int64(100).toInt(), 100); | 663 expect(new Int64(100).toInt(), 100); |
| 651 expect(new Int64(-100).toInt(), -100); | 664 expect(new Int64(-100).toInt(), -100); |
| 652 expect(new Int64(2147483647).toInt(), 2147483647); | 665 expect(new Int64(2147483647).toInt(), 2147483647); |
| 653 expect(new Int64(2147483648).toInt(), 2147483648); | 666 expect(new Int64(2147483648).toInt(), 2147483648); |
| 654 expect(new Int64(-2147483647).toInt(), -2147483647); | 667 expect(new Int64(-2147483647).toInt(), -2147483647); |
| 655 expect(new Int64(-2147483648).toInt(), -2147483648); | 668 expect(new Int64(-2147483648).toInt(), -2147483648); |
| 656 expect(new Int64(4503599627370495).toInt(), 4503599627370495); | 669 expect(new Int64(4503599627370495).toInt(), 4503599627370495); |
| 657 expect(new Int64(4503599627370496).toInt(), 4503599627370496); | 670 expect(new Int64(4503599627370496).toInt(), 4503599627370496); |
| 658 expect(new Int64(-4503599627370495).toInt(), -4503599627370495); | 671 expect(new Int64(-4503599627370495).toInt(), -4503599627370495); |
| 659 expect(new Int64(-4503599627370496).toInt(), -4503599627370496); | 672 expect(new Int64(-4503599627370496).toInt(), -4503599627370496); |
| 660 expect(Int64 | 673 expect(Int64.parseInt("-10000000000000000").toInt(), |
| 661 .parseInt("-10000000000000000") | 674 same(-10000000000000000)); |
| 662 .toInt(), same(-10000000000000000)); | |
| 663 expect(Int64.parseInt("-10000000000000001").toInt(), | 675 expect(Int64.parseInt("-10000000000000001").toInt(), |
| 664 same(-10000000000000001)); | 676 same(-10000000000000001)); |
| 665 expect(Int64.parseInt("-10000000000000002").toInt(), | 677 expect(Int64.parseInt("-10000000000000002").toInt(), |
| 666 same(-10000000000000002)); | 678 same(-10000000000000002)); |
| 667 expect(Int64.parseInt("-10000000000000003").toInt(), | 679 expect(Int64.parseInt("-10000000000000003").toInt(), |
| 668 same(-10000000000000003)); | 680 same(-10000000000000003)); |
| 669 expect(Int64.parseInt("-10000000000000004").toInt(), | 681 expect(Int64.parseInt("-10000000000000004").toInt(), |
| 670 same(-10000000000000004)); | 682 same(-10000000000000004)); |
| 671 expect(Int64.parseInt("-10000000000000005").toInt(), | 683 expect(Int64.parseInt("-10000000000000005").toInt(), |
| 672 same(-10000000000000005)); | 684 same(-10000000000000005)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 check(String s, int r, String x) { | 780 check(String s, int r, String x) { |
| 769 expect(Int64.parseRadix(s, r).toString(), x); | 781 expect(Int64.parseRadix(s, r).toString(), x); |
| 770 } | 782 } |
| 771 check('ghoul', 36, '27699213'); | 783 check('ghoul', 36, '27699213'); |
| 772 check('ghoul', 35, '24769346'); | 784 check('ghoul', 35, '24769346'); |
| 773 // Min and max value. | 785 // Min and max value. |
| 774 check("-9223372036854775808", 10, "-9223372036854775808"); | 786 check("-9223372036854775808", 10, "-9223372036854775808"); |
| 775 check("9223372036854775807", 10, "9223372036854775807"); | 787 check("9223372036854775807", 10, "9223372036854775807"); |
| 776 // Overflow during parsing. | 788 // Overflow during parsing. |
| 777 check("9223372036854775808", 10, "-9223372036854775808"); | 789 check("9223372036854775808", 10, "-9223372036854775808"); |
| 790 |
| 791 expect(() => Int64.parseRadix('0', 1), throwsRangeError); |
| 792 expect(() => Int64.parseRadix('0', 37), throwsRangeError); |
| 793 expect(() => Int64.parseRadix('xyzzy', -1), throwsRangeError); |
| 794 expect(() => Int64.parseRadix('xyzzy', 10), throwsFormatException); |
| 778 }); | 795 }); |
| 779 | 796 |
| 780 test("parseRadixN", () { | 797 test("parseRadixN", () { |
| 781 check(String s, int r) { | 798 check(String s, int r) { |
| 782 expect(Int64.parseRadix(s, r).toRadixString(r), s); | 799 expect(Int64.parseRadix(s, r).toRadixString(r), s); |
| 783 } | 800 } |
| 784 check("2ppp111222333", 33); // This value & radix requires three chunks. | 801 check("2ppp111222333", 33); // This value & radix requires three chunks. |
| 785 }); | 802 }); |
| 786 }); | 803 }); |
| 787 | 804 |
| 788 group("string representation", () { | 805 group("string representation", () { |
| 789 test("toString", () { | 806 test("toString", () { |
| 790 expect(new Int64(0).toString(), "0"); | 807 expect(new Int64(0).toString(), "0"); |
| 791 expect(new Int64(1).toString(), "1"); | 808 expect(new Int64(1).toString(), "1"); |
| 792 expect(new Int64(-1).toString(), "-1"); | 809 expect(new Int64(-1).toString(), "-1"); |
| 793 expect(new Int64(-10).toString(), "-10"); | 810 expect(new Int64(-10).toString(), "-10"); |
| 794 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); | 811 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); | 846 expect(Int64.MIN_VALUE.toRadixString(11), "-1728002635214590698"); |
| 830 expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368"); | 847 expect(Int64.MIN_VALUE.toRadixString(12), "-41a792678515120368"); |
| 831 expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38"); | 848 expect(Int64.MIN_VALUE.toRadixString(13), "-10b269549075433c38"); |
| 832 expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8"); | 849 expect(Int64.MIN_VALUE.toRadixString(14), "-4340724c6c71dc7a8"); |
| 833 expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808"); | 850 expect(Int64.MIN_VALUE.toRadixString(15), "-160e2ad3246366808"); |
| 834 expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); | 851 expect(Int64.MIN_VALUE.toRadixString(16), "-8000000000000000"); |
| 835 expect(Int64.MAX_VALUE.toRadixString(2), | 852 expect(Int64.MAX_VALUE.toRadixString(2), |
| 836 "111111111111111111111111111111111111111111111111111111111111111"); | 853 "111111111111111111111111111111111111111111111111111111111111111"); |
| 837 expect(Int64.MAX_VALUE.toRadixString(3), | 854 expect(Int64.MAX_VALUE.toRadixString(3), |
| 838 "2021110011022210012102010021220101220221"); | 855 "2021110011022210012102010021220101220221"); |
| 839 expect( | 856 expect(Int64.MAX_VALUE.toRadixString(4), |
| 840 Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333"); | 857 "13333333333333333333333333333333"); |
| 841 expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); | 858 expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212"); |
| 842 expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); | 859 expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211"); |
| 843 expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); | 860 expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300"); |
| 844 expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); | 861 expect(Int64.MAX_VALUE.toRadixString(8), "777777777777777777777"); |
| 845 expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); | 862 expect(Int64.MAX_VALUE.toRadixString(9), "67404283172107811827"); |
| 846 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); | 863 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); |
| 847 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); | 864 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); |
| 848 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); | 865 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); |
| 849 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); | 866 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); |
| 850 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); | 867 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); |
| 851 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); | 868 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); |
| 852 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); | 869 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); |
| 853 expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); | 870 expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); |
| 854 expect(() => new Int64(42).toRadixString(0), throwsArgumentError); | 871 expect(() => new Int64(42).toRadixString(0), throwsArgumentError); |
| 855 expect(() => new Int64(42).toRadixString(37), throwsArgumentError); | 872 expect(() => new Int64(42).toRadixString(37), throwsArgumentError); |
| 856 }); | 873 }); |
| 857 }); | 874 }); |
| 858 } | 875 } |
| OLD | NEW |