| 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 Int32test; | 5 library Int32test; |
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 expect(Int32.MAX_VALUE.bitLength, 31); | 50 expect(Int32.MAX_VALUE.bitLength, 31); |
| 51 expect(Int32.MIN_VALUE.bitLength, 31); | 51 expect(Int32.MIN_VALUE.bitLength, 31); |
| 52 }); | 52 }); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 group("arithmetic operators", () { | 55 group("arithmetic operators", () { |
| 56 Int32 n1 = new Int32(1234); | 56 Int32 n1 = new Int32(1234); |
| 57 Int32 n2 = new Int32(9876); | 57 Int32 n2 = new Int32(9876); |
| 58 Int32 n3 = new Int32(-1234); | 58 Int32 n3 = new Int32(-1234); |
| 59 Int32 n4 = new Int32(-9876); | 59 Int32 n4 = new Int32(-9876); |
| 60 Int32 n5 = new Int32(0x12345678); | |
| 61 Int32 n6 = new Int32(0x22222222); | |
| 62 | 60 |
| 63 test("+", () { | 61 test("+", () { |
| 64 expect(n1 + n2, new Int32(11110)); | 62 expect(n1 + n2, new Int32(11110)); |
| 65 expect(n3 + n2, new Int32(8642)); | 63 expect(n3 + n2, new Int32(8642)); |
| 66 expect(n3 + n4, new Int32(-11110)); | 64 expect(n3 + n4, new Int32(-11110)); |
| 67 expect(n3 + new Int64(1), new Int64(-1233)); | 65 expect(n3 + new Int64(1), new Int64(-1233)); |
| 68 expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); | 66 expect(Int32.MAX_VALUE + 1, Int32.MIN_VALUE); |
| 69 expect(() => new Int32(17) + null, throws); | 67 expect(() => new Int32(17) + null, throws); |
| 70 }); | 68 }); |
| 71 | 69 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 }); | 308 }); |
| 311 | 309 |
| 312 group("conversions", () { | 310 group("conversions", () { |
| 313 test("toSigned", () { | 311 test("toSigned", () { |
| 314 expect(Int32.ONE.toSigned(2), Int32.ONE); | 312 expect(Int32.ONE.toSigned(2), Int32.ONE); |
| 315 expect(Int32.ONE.toSigned(1), -Int32.ONE); | 313 expect(Int32.ONE.toSigned(1), -Int32.ONE); |
| 316 expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE); | 314 expect(Int32.MAX_VALUE.toSigned(32), Int32.MAX_VALUE); |
| 317 expect(Int32.MIN_VALUE.toSigned(32), Int32.MIN_VALUE); | 315 expect(Int32.MIN_VALUE.toSigned(32), Int32.MIN_VALUE); |
| 318 expect(Int32.MAX_VALUE.toSigned(31), -Int32.ONE); | 316 expect(Int32.MAX_VALUE.toSigned(31), -Int32.ONE); |
| 319 expect(Int32.MIN_VALUE.toSigned(31), Int32.ZERO); | 317 expect(Int32.MIN_VALUE.toSigned(31), Int32.ZERO); |
| 320 expect(() => Int32.ONE.toSigned(0), throws); | 318 expect(() => Int32.ONE.toSigned(0), throwsRangeError); |
| 321 expect(() => Int32.ONE.toSigned(33), throws); | 319 expect(() => Int32.ONE.toSigned(33), throwsRangeError); |
| 322 }); | 320 }); |
| 323 test("toUnsigned", () { | 321 test("toUnsigned", () { |
| 324 expect(Int32.ONE.toUnsigned(1), Int32.ONE); | 322 expect(Int32.ONE.toUnsigned(1), Int32.ONE); |
| 325 expect(Int32.ONE.toUnsigned(0), Int32.ZERO); | 323 expect(Int32.ONE.toUnsigned(0), Int32.ZERO); |
| 326 expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE); | 324 expect(Int32.MAX_VALUE.toUnsigned(32), Int32.MAX_VALUE); |
| 327 expect(Int32.MIN_VALUE.toUnsigned(32), Int32.MIN_VALUE); | 325 expect(Int32.MIN_VALUE.toUnsigned(32), Int32.MIN_VALUE); |
| 328 expect(Int32.MAX_VALUE.toUnsigned(31), Int32.MAX_VALUE); | 326 expect(Int32.MAX_VALUE.toUnsigned(31), Int32.MAX_VALUE); |
| 329 expect(Int32.MIN_VALUE.toUnsigned(31), Int32.ZERO); | 327 expect(Int32.MIN_VALUE.toUnsigned(31), Int32.ZERO); |
| 330 expect(() => Int32.ONE.toUnsigned(-1), throws); | 328 expect(() => Int32.ONE.toUnsigned(-1), throwsRangeError); |
| 331 expect(() => Int32.ONE.toUnsigned(33), throws); | 329 expect(() => Int32.ONE.toUnsigned(33), throwsRangeError); |
| 332 }); | 330 }); |
| 333 test("toDouble", () { | 331 test("toDouble", () { |
| 334 expect(new Int32(17).toDouble(), same(17.0)); | 332 expect(new Int32(17).toDouble(), same(17.0)); |
| 335 expect(new Int32(-17).toDouble(), same(-17.0)); | 333 expect(new Int32(-17).toDouble(), same(-17.0)); |
| 336 }); | 334 }); |
| 337 test("toInt", () { | 335 test("toInt", () { |
| 338 expect(new Int32(17).toInt(), 17); | 336 expect(new Int32(17).toInt(), 17); |
| 339 expect(new Int32(-17).toInt(), -17); | 337 expect(new Int32(-17).toInt(), -17); |
| 340 }); | 338 }); |
| 341 test("toInt32", () { | 339 test("toInt32", () { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); | 418 expect(new Int32(-1).shiftRightUnsigned(8).toHexString(), "ffffff"); |
| 421 }); | 419 }); |
| 422 }); | 420 }); |
| 423 | 421 |
| 424 group("toRadixString", () { | 422 group("toRadixString", () { |
| 425 test("returns base n string representation", () { | 423 test("returns base n string representation", () { |
| 426 expect(new Int32(123456789).toRadixString(5), "223101104124"); | 424 expect(new Int32(123456789).toRadixString(5), "223101104124"); |
| 427 }); | 425 }); |
| 428 }); | 426 }); |
| 429 } | 427 } |
| OLD | NEW |