| 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 import 'package:fixnum/fixnum.dart'; | 6 import 'package:fixnum/fixnum.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 void main() { | 9 void main() { |
| 10 group("arithmetic operators", () { | 10 group("arithmetic operators", () { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 test("*", () { | 39 test("*", () { |
| 40 expect(new Int64.fromInt(1111) * new Int64.fromInt(3), | 40 expect(new Int64.fromInt(1111) * new Int64.fromInt(3), |
| 41 new Int64.fromInt(3333)); | 41 new Int64.fromInt(3333)); |
| 42 expect(new Int64.fromInt(1111) * new Int64.fromInt(-3), | 42 expect(new Int64.fromInt(1111) * new Int64.fromInt(-3), |
| 43 new Int64.fromInt(-3333)); | 43 new Int64.fromInt(-3333)); |
| 44 expect(new Int64.fromInt(-1111) * new Int64.fromInt(3), | 44 expect(new Int64.fromInt(-1111) * new Int64.fromInt(3), |
| 45 new Int64.fromInt(-3333)); | 45 new Int64.fromInt(-3333)); |
| 46 expect(new Int64.fromInt(-1111) * new Int64.fromInt(-3), | 46 expect(new Int64.fromInt(-1111) * new Int64.fromInt(-3), |
| 47 new Int64.fromInt(3333)); | 47 new Int64.fromInt(3333)); |
| 48 expect(new Int64.fromInt(100) * new Int64.fromInt(0), | 48 expect(new Int64.fromInt(100) * Int64.ZERO, |
| 49 new Int64.fromInt(0)); | 49 Int64.ZERO); |
| 50 | 50 |
| 51 expect(new Int64.fromInts(0x12345678, 0x12345678) * | 51 expect(new Int64.fromInts(0x12345678, 0x12345678) * |
| 52 new Int64.fromInts(0x1234, 0x12345678), | 52 new Int64.fromInts(0x1234, 0x12345678), |
| 53 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 53 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
| 54 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 54 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
| 55 new Int64.fromInts(0x1234, 0x12345678), | 55 new Int64.fromInts(0x1234, 0x12345678), |
| 56 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 56 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
| 57 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 57 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
| 58 new Int64.fromInts(0xffff1234, 0x12345678), | 58 new Int64.fromInts(0xffff1234, 0x12345678), |
| 59 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); | 59 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); |
| 60 | 60 |
| 61 // RHS Int32 | 61 // RHS Int32 |
| 62 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), | 62 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), |
| 63 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 63 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 64 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), | 64 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), |
| 65 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 65 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 66 | 66 |
| 67 // Wraparound | 67 // Wraparound |
| 68 expect((new Int64.fromInt(123456789) * new Int64.fromInt(987654321)), | 68 expect((new Int64.fromInt(123456789) * new Int64.fromInt(987654321)), |
| 69 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 69 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 70 | 70 |
| 71 expect(Int64.MIN_VALUE * new Int64.fromInt(2), new Int64.fromInt(0)); | 71 expect(Int64.MIN_VALUE * new Int64.fromInt(2), Int64.ZERO); |
| 72 expect(Int64.MIN_VALUE * new Int64.fromInt(1), Int64.MIN_VALUE); | 72 expect(Int64.MIN_VALUE * new Int64.fromInt(1), Int64.MIN_VALUE); |
| 73 expect(Int64.MIN_VALUE * new Int64.fromInt(-1), Int64.MIN_VALUE); | 73 expect(Int64.MIN_VALUE * new Int64.fromInt(-1), Int64.MIN_VALUE); |
| 74 }); | 74 }); |
| 75 | 75 |
| 76 test("~/", () { | 76 test("~/", () { |
| 77 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); | 77 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); |
| 78 Int64 ten = new Int64.fromInt(10); | 78 Int64 ten = new Int64.fromInt(10); |
| 79 | 79 |
| 80 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); | 80 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); |
| 81 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); | 81 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 new Int64.fromInt(1)); | 126 new Int64.fromInt(1)); |
| 127 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(3), | 127 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(3), |
| 128 new Int64.fromInt(333)); | 128 new Int64.fromInt(333)); |
| 129 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(-3), | 129 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(-3), |
| 130 new Int64.fromInt(-333)); | 130 new Int64.fromInt(-333)); |
| 131 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(3), | 131 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(3), |
| 132 new Int64.fromInt(-333)); | 132 new Int64.fromInt(-333)); |
| 133 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(-3), | 133 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(-3), |
| 134 new Int64.fromInt(333)); | 134 new Int64.fromInt(333)); |
| 135 expect(new Int64.fromInt(3) ~/ new Int64.fromInt(1000), | 135 expect(new Int64.fromInt(3) ~/ new Int64.fromInt(1000), |
| 136 new Int64.fromInt(0)); | 136 Int64.ZERO); |
| 137 expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ | 137 expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ |
| 138 new Int64.fromInts(0x0, 0x123), | 138 new Int64.fromInts(0x0, 0x123), |
| 139 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); | 139 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); |
| 140 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ | 140 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ |
| 141 new Int64.fromInts(0x1234, 0x12345678), | 141 new Int64.fromInts(0x1234, 0x12345678), |
| 142 new Int64.fromInts(0x0, 0x10003)); | 142 new Int64.fromInts(0x0, 0x10003)); |
| 143 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 143 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
| 144 new Int64.fromInts(0x1234, 0x12345678), | 144 new Int64.fromInts(0x1234, 0x12345678), |
| 145 new Int64.fromInts(0xffffffff, 0xffff3dfe)); | 145 new Int64.fromInts(0xffffffff, 0xffff3dfe)); |
| 146 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 146 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
| 147 new Int64.fromInts(0xffff1234, 0x12345678), | 147 new Int64.fromInts(0xffff1234, 0x12345678), |
| 148 new Int64.fromInts(0x0, 0xeda)); | 148 new Int64.fromInts(0x0, 0xeda)); |
| 149 expect(new Int64.fromInt(829893893) ~/ new Int32.fromInt(1919), | 149 expect(new Int64.fromInt(829893893) ~/ new Int32.fromInt(1919), |
| 150 new Int32.fromInt(432461)); | 150 new Int32.fromInt(432461)); |
| 151 expect(new Int64.fromInt(829893893) ~/ new Int64.fromInt(1919), | 151 expect(new Int64.fromInt(829893893) ~/ new Int64.fromInt(1919), |
| 152 new Int32.fromInt(432461)); | 152 new Int32.fromInt(432461)); |
| 153 expect(new Int64.fromInt(829893893) ~/ 1919, | 153 expect(new Int64.fromInt(829893893) ~/ 1919, |
| 154 new Int32.fromInt(432461)); | 154 new Int32.fromInt(432461)); |
| 155 expect(() => new Int64.fromInt(1) ~/ new Int64.fromInt(0), | 155 expect(() => new Int64.fromInt(1) ~/ Int64.ZERO, |
| 156 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); | 156 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); |
| 157 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(2), | 157 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(2), |
| 158 new Int64.fromInts(0xc0000000, 0x00000000)); | 158 new Int64.fromInts(0xc0000000, 0x00000000)); |
| 159 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(1), Int64.MIN_VALUE); | 159 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(1), Int64.MIN_VALUE); |
| 160 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(-1), Int64.MIN_VALUE); | 160 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(-1), Int64.MIN_VALUE); |
| 161 expect(() => new Int64.fromInt(17) ~/ Int64.ZERO, throws); | 161 expect(() => new Int64.fromInt(17) ~/ Int64.ZERO, throws); |
| 162 expect(() => new Int64.fromInt(17) ~/ null, throwsArgumentError); | 162 expect(() => new Int64.fromInt(17) ~/ null, throwsArgumentError); |
| 163 }); | 163 }); |
| 164 | 164 |
| 165 test("%", () { | 165 test("%", () { |
| 166 // Define % as Euclidean mod, with positive result for all arguments | 166 // Define % as Euclidean mod, with positive result for all arguments |
| 167 expect(Int64.ZERO % new Int64.fromInt(1000), new Int64.fromInt(0)); | 167 expect(Int64.ZERO % new Int64.fromInt(1000), Int64.ZERO); |
| 168 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, new Int64.fromInt(0)); | 168 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); |
| 169 expect(new Int64.fromInt(1000) % Int64.MIN_VALUE, | 169 expect(new Int64.fromInt(1000) % Int64.MIN_VALUE, |
| 170 new Int64.fromInt(1000)); | 170 new Int64.fromInt(1000)); |
| 171 expect(Int64.MIN_VALUE % new Int64.fromInt(8192), new Int64.fromInt(0)); | 171 expect(Int64.MIN_VALUE % new Int64.fromInt(8192), Int64.ZERO); |
| 172 expect(Int64.MIN_VALUE % new Int64.fromInt(8193), | 172 expect(Int64.MIN_VALUE % new Int64.fromInt(8193), |
| 173 new Int64.fromInt(6145)); | 173 new Int64.fromInt(6145)); |
| 174 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8192), | 174 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8192), |
| 175 new Int64.fromInt(7192)); | 175 new Int64.fromInt(7192)); |
| 176 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8193), | 176 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8193), |
| 177 new Int64.fromInt(7193)); | 177 new Int64.fromInt(7193)); |
| 178 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8192), | 178 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8192), |
| 179 new Int64.fromInt(5632)); | 179 new Int64.fromInt(5632)); |
| 180 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8193), | 180 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8193), |
| 181 new Int64.fromInt(4808)); | 181 new Int64.fromInt(4808)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 Int64 largePosPlusOne = largePos + new Int64.fromInt(1); | 216 Int64 largePosPlusOne = largePos + new Int64.fromInt(1); |
| 217 | 217 |
| 218 test("<", () { | 218 test("<", () { |
| 219 expect(new Int64.fromInt(10) < new Int64.fromInt(11), true); | 219 expect(new Int64.fromInt(10) < new Int64.fromInt(11), true); |
| 220 expect(new Int64.fromInt(10) < new Int64.fromInt(10), false); | 220 expect(new Int64.fromInt(10) < new Int64.fromInt(10), false); |
| 221 expect(new Int64.fromInt(10) < new Int64.fromInt(9), false); | 221 expect(new Int64.fromInt(10) < new Int64.fromInt(9), false); |
| 222 expect(new Int64.fromInt(10) < new Int32.fromInt(11), true); | 222 expect(new Int64.fromInt(10) < new Int32.fromInt(11), true); |
| 223 expect(new Int64.fromInt(10) < new Int32.fromInt(10), false); | 223 expect(new Int64.fromInt(10) < new Int32.fromInt(10), false); |
| 224 expect(new Int64.fromInt(10) < new Int32.fromInt(9), false); | 224 expect(new Int64.fromInt(10) < new Int32.fromInt(9), false); |
| 225 expect(new Int64.fromInt(-10) < new Int64.fromInt(-11), false); | 225 expect(new Int64.fromInt(-10) < new Int64.fromInt(-11), false); |
| 226 expect(Int64.MIN_VALUE < new Int64.fromInt(0), true); | 226 expect(Int64.MIN_VALUE < Int64.ZERO, true); |
| 227 expect(largeNeg < largePos, true); | 227 expect(largeNeg < largePos, true); |
| 228 expect(largePos < largePosPlusOne, true); | 228 expect(largePos < largePosPlusOne, true); |
| 229 expect(largePos < largePos, false); | 229 expect(largePos < largePos, false); |
| 230 expect(largePosPlusOne < largePos, false); | 230 expect(largePosPlusOne < largePos, false); |
| 231 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); | 231 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); |
| 232 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); | 232 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); |
| 233 expect(() => new Int64.fromInt(17) < null, throwsArgumentError); | 233 expect(() => new Int64.fromInt(17) < null, throwsArgumentError); |
| 234 }); | 234 }); |
| 235 | 235 |
| 236 test("<=", () { | 236 test("<=", () { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 expect(new Int64.fromInt(10) > new Int32.fromInt(10), false); | 296 expect(new Int64.fromInt(10) > new Int32.fromInt(10), false); |
| 297 expect(new Int64.fromInt(10) > new Int32.fromInt(9), true); | 297 expect(new Int64.fromInt(10) > new Int32.fromInt(9), true); |
| 298 expect(new Int64.fromInt(-10) > new Int64.fromInt(-11), true); | 298 expect(new Int64.fromInt(-10) > new Int64.fromInt(-11), true); |
| 299 expect(new Int64.fromInt(10) > new Int64.fromInt(-11), true); | 299 expect(new Int64.fromInt(10) > new Int64.fromInt(-11), true); |
| 300 expect(new Int64.fromInt(-10) > new Int64.fromInt(11), false); | 300 expect(new Int64.fromInt(-10) > new Int64.fromInt(11), false); |
| 301 expect(largePos > largeNeg, true); | 301 expect(largePos > largeNeg, true); |
| 302 expect(largeNeg > largePos, false); | 302 expect(largeNeg > largePos, false); |
| 303 expect(largePos > largePosPlusOne, false); | 303 expect(largePos > largePosPlusOne, false); |
| 304 expect(largePos > largePos, false); | 304 expect(largePos > largePos, false); |
| 305 expect(largePosPlusOne > largePos, true); | 305 expect(largePosPlusOne > largePos, true); |
| 306 expect(new Int64.fromInt(0) > Int64.MIN_VALUE, true); | 306 expect(Int64.ZERO > Int64.MIN_VALUE, true); |
| 307 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); | 307 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); |
| 308 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); | 308 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); |
| 309 expect(() => new Int64.fromInt(17) > null, throwsArgumentError); | 309 expect(() => new Int64.fromInt(17) > null, throwsArgumentError); |
| 310 }); | 310 }); |
| 311 }); | 311 }); |
| 312 | 312 |
| 313 group("bitwise operators", () { | 313 group("bitwise operators", () { |
| 314 Int64 n1 = new Int64.fromInt(1234); | 314 Int64 n1 = new Int64.fromInt(1234); |
| 315 Int64 n2 = new Int64.fromInt(9876); | 315 Int64 n2 = new Int64.fromInt(9876); |
| 316 Int64 n3 = new Int64.fromInt(-1234); | 316 Int64 n3 = new Int64.fromInt(-1234); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); | 632 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); |
| 633 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); | 633 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); |
| 634 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); | 634 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); |
| 635 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); | 635 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); |
| 636 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); | 636 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); |
| 637 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); | 637 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); |
| 638 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); | 638 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); |
| 639 }); | 639 }); |
| 640 }); | 640 }); |
| 641 } | 641 } |
| OLD | NEW |