| 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", () { |
| 11 Int64 n1 = new Int64.fromInt(1234); | 11 Int64 n1 = new Int64(1234); |
| 12 Int64 n2 = new Int64.fromInt(9876); | 12 Int64 n2 = new Int64(9876); |
| 13 Int64 n3 = new Int64.fromInt(-1234); | 13 Int64 n3 = new Int64(-1234); |
| 14 Int64 n4 = new Int64.fromInt(-9876); | 14 Int64 n4 = new Int64(-9876); |
| 15 Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); | 15 Int64 n5 = new Int64.fromInts(0x12345678, 0xabcdabcd); |
| 16 Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); | 16 Int64 n6 = new Int64.fromInts(0x77773333, 0x22224444); |
| 17 | 17 |
| 18 test("+", () { | 18 test("+", () { |
| 19 expect(n1 + n2, new Int64.fromInt(11110)); | 19 expect(n1 + n2, new Int64(11110)); |
| 20 expect(n3 + n2, new Int64.fromInt(8642)); | 20 expect(n3 + n2, new Int64(8642)); |
| 21 expect(n3 + n4, new Int64.fromInt(-11110)); | 21 expect(n3 + n4, new Int64(-11110)); |
| 22 expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); | 22 expect(n5 + n6, new Int64.fromInts(0x89ab89ab, 0xcdeff011)); |
| 23 expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); | 23 expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE); |
| 24 }); | 24 }); |
| 25 | 25 |
| 26 test("-", () { | 26 test("-", () { |
| 27 expect(n1 - n2, new Int64.fromInt(-8642)); | 27 expect(n1 - n2, new Int64(-8642)); |
| 28 expect(n3 - n2, new Int64.fromInt(-11110)); | 28 expect(n3 - n2, new Int64(-11110)); |
| 29 expect(n3 - n4, new Int64.fromInt(8642)); | 29 expect(n3 - n4, new Int64(8642)); |
| 30 expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); | 30 expect(n5 - n6, new Int64.fromInts(0x9abd2345, 0x89ab6789)); |
| 31 expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); | 31 expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 test("unary -", () { | 34 test("unary -", () { |
| 35 expect(-n1, new Int64.fromInt(-1234)); | 35 expect(-n1, new Int64(-1234)); |
| 36 expect(-Int64.ZERO, Int64.ZERO); | 36 expect(-Int64.ZERO, Int64.ZERO); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 test("*", () { | 39 test("*", () { |
| 40 expect(new Int64.fromInt(1111) * new Int64.fromInt(3), | 40 expect(new Int64(1111) * new Int64(3), new Int64(3333)); |
| 41 new Int64.fromInt(3333)); | 41 expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); |
| 42 expect(new Int64.fromInt(1111) * new Int64.fromInt(-3), | 42 expect(new Int64(-1111) * new Int64(3), new Int64(-3333)); |
| 43 new Int64.fromInt(-3333)); | 43 expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); |
| 44 expect(new Int64.fromInt(-1111) * new Int64.fromInt(3), | 44 expect(new Int64(100) * Int64.ZERO, Int64.ZERO); |
| 45 new Int64.fromInt(-3333)); | |
| 46 expect(new Int64.fromInt(-1111) * new Int64.fromInt(-3), | |
| 47 new Int64.fromInt(3333)); | |
| 48 expect(new Int64.fromInt(100) * Int64.ZERO, | |
| 49 Int64.ZERO); | |
| 50 | 45 |
| 51 expect(new Int64.fromInts(0x12345678, 0x12345678) * | 46 expect(new Int64.fromInts(0x12345678, 0x12345678) * |
| 52 new Int64.fromInts(0x1234, 0x12345678), | 47 new Int64.fromInts(0x1234, 0x12345678), |
| 53 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 48 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
| 54 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 49 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
| 55 new Int64.fromInts(0x1234, 0x12345678), | 50 new Int64.fromInts(0x1234, 0x12345678), |
| 56 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 51 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
| 57 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 52 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
| 58 new Int64.fromInts(0xffff1234, 0x12345678), | 53 new Int64.fromInts(0xffff1234, 0x12345678), |
| 59 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); | 54 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); |
| 60 | 55 |
| 61 // RHS Int32 | 56 // RHS Int32 |
| 62 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), | 57 expect((new Int64(123456789) * new Int32(987654321)), |
| 63 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 58 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 64 expect((new Int64.fromInt(123456789) * new Int32.fromInt(987654321)), | 59 expect((new Int64(123456789) * new Int32(987654321)), |
| 65 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 60 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 66 | 61 |
| 67 // Wraparound | 62 // Wraparound |
| 68 expect((new Int64.fromInt(123456789) * new Int64.fromInt(987654321)), | 63 expect((new Int64(123456789) * new Int64(987654321)), |
| 69 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 64 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
| 70 | 65 |
| 71 expect(Int64.MIN_VALUE * new Int64.fromInt(2), Int64.ZERO); | 66 expect(Int64.MIN_VALUE * new Int64(2), Int64.ZERO); |
| 72 expect(Int64.MIN_VALUE * new Int64.fromInt(1), Int64.MIN_VALUE); | 67 expect(Int64.MIN_VALUE * new Int64(1), Int64.MIN_VALUE); |
| 73 expect(Int64.MIN_VALUE * new Int64.fromInt(-1), Int64.MIN_VALUE); | 68 expect(Int64.MIN_VALUE * new Int64(-1), Int64.MIN_VALUE); |
| 74 }); | 69 }); |
| 75 | 70 |
| 76 test("~/", () { | 71 test("~/", () { |
| 77 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); | 72 Int64 deadBeef = new Int64.fromInts(0xDEADBEEF, 0xDEADBEEF); |
| 78 Int64 ten = new Int64.fromInt(10); | 73 Int64 ten = new Int64(10); |
| 79 | 74 |
| 80 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); | 75 expect(deadBeef ~/ ten, new Int64.fromInts(0xfcaaf97e, 0x63115fe5)); |
| 81 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); | 76 expect(Int64.ONE ~/ Int64.TWO, Int64.ZERO); |
| 82 expect(Int64.MAX_VALUE ~/ Int64.TWO, | 77 expect(Int64.MAX_VALUE ~/ Int64.TWO, |
| 83 new Int64.fromInts(0x3fffffff, 0xffffffff)); | 78 new Int64.fromInts(0x3fffffff, 0xffffffff)); |
| 84 expect(Int64.ZERO ~/ new Int64.fromInt(1000), Int64.ZERO); | 79 expect(Int64.ZERO ~/ new Int64(1000), Int64.ZERO); |
| 85 expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE); | 80 expect(Int64.MIN_VALUE ~/ Int64.MIN_VALUE, Int64.ONE); |
| 86 expect(new Int64.fromInt(1000) ~/ Int64.MIN_VALUE, Int64.ZERO); | 81 expect(new Int64(1000) ~/ Int64.MIN_VALUE, Int64.ZERO); |
| 87 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(8192), | 82 expect(Int64.MIN_VALUE ~/ new Int64(8192), new Int64(-1125899906842624)); |
| 88 new Int64.fromInt(-1125899906842624)); | 83 expect(Int64.MIN_VALUE ~/ new Int64(8193), new Int64(-1125762484664320)); |
| 89 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(8193), | 84 expect(new Int64(-1000) ~/ new Int64(8192), Int64.ZERO); |
| 90 new Int64.fromInt(-1125762484664320)); | 85 expect(new Int64(-1000) ~/ new Int64(8193), Int64.ZERO); |
| 91 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(8192), Int64.ZERO); | 86 expect(new Int64(-1000000000) ~/ new Int64(8192), new Int64(-122070)); |
| 92 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(8193), Int64.ZERO); | 87 expect(new Int64(-1000000000) ~/ new Int64(8193), new Int64(-122055)); |
| 93 expect(new Int64.fromInt(-1000000000) ~/ new Int64.fromInt(8192), | 88 expect(new Int64(1000000000) ~/ new Int64(8192), new Int64(122070)); |
| 94 new Int64.fromInt(-122070)); | 89 expect(new Int64(1000000000) ~/ new Int64(8193), new Int64(122055)); |
| 95 expect(new Int64.fromInt(-1000000000) ~/ new Int64.fromInt(8193), | |
| 96 new Int64.fromInt(-122055)); | |
| 97 expect(new Int64.fromInt(1000000000) ~/ new Int64.fromInt(8192), | |
| 98 new Int64.fromInt(122070)); | |
| 99 expect(new Int64.fromInt(1000000000) ~/ new Int64.fromInt(8193), | |
| 100 new Int64.fromInt(122055)); | |
| 101 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400), | 90 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000400), |
| 102 new Int64.fromInts(0x1fffff, 0xffffffff)); | 91 new Int64.fromInts(0x1fffff, 0xffffffff)); |
| 103 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000), | 92 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00040000), |
| 104 new Int64.fromInts(0x1fff, 0xffffffff)); | 93 new Int64.fromInts(0x1fff, 0xffffffff)); |
| 105 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000), | 94 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x04000000), |
| 106 new Int64.fromInts(0x1f, 0xffffffff)); | 95 new Int64.fromInts(0x1f, 0xffffffff)); |
| 107 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000), | 96 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000004, 0x00000000), |
| 108 new Int64.fromInt(536870911)); | 97 new Int64(536870911)); |
| 109 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000), | 98 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000400, 0x00000000), |
| 110 new Int64.fromInt(2097151)); | 99 new Int64(2097151)); |
| 111 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000), | 100 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00040000, 0x00000000), |
| 112 new Int64.fromInt(8191)); | 101 new Int64(8191)); |
| 113 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000), | 102 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x04000000, 0x00000000), |
| 114 new Int64.fromInt(31)); | 103 new Int64(31)); |
| 115 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300), | 104 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x00000300), |
| 116 new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA)); | 105 new Int64.fromInts(0x2AAAAA, 0xAAAAAAAA)); |
| 117 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000), | 106 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00000000, 0x30000000), |
| 118 new Int64.fromInts(0x2, 0xAAAAAAAA)); | 107 new Int64.fromInts(0x2, 0xAAAAAAAA)); |
| 119 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000), | 108 expect(Int64.MAX_VALUE ~/ new Int64.fromInts(0x00300000, 0x00000000), |
| 120 new Int64.fromInt(0x2AA)); | 109 new Int64(0x2AA)); |
| 121 expect(Int64.MAX_VALUE ~/ new Int64.fromInt(0x123456), | 110 expect(Int64.MAX_VALUE ~/ new Int64(0x123456), |
| 122 new Int64.fromInts(0x708, 0x002E9501)); | 111 new Int64.fromInts(0x708, 0x002E9501)); |
| 123 expect(Int64.MAX_VALUE % new Int64.fromInt(0x123456), | 112 expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9)); |
| 124 new Int64.fromInt(0x3BDA9)); | 113 expect(new Int64(5) ~/ new Int64(5), Int64.ONE); |
| 125 expect(new Int64.fromInt(5) ~/ new Int64.fromInt(5), | 114 expect(new Int64(1000) ~/ new Int64(3), new Int64(333)); |
| 126 new Int64.fromInt(1)); | 115 expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333)); |
| 127 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(3), | 116 expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); |
| 128 new Int64.fromInt(333)); | 117 expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); |
| 129 expect(new Int64.fromInt(1000) ~/ new Int64.fromInt(-3), | 118 expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); |
| 130 new Int64.fromInt(-333)); | |
| 131 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(3), | |
| 132 new Int64.fromInt(-333)); | |
| 133 expect(new Int64.fromInt(-1000) ~/ new Int64.fromInt(-3), | |
| 134 new Int64.fromInt(333)); | |
| 135 expect(new Int64.fromInt(3) ~/ new Int64.fromInt(1000), | |
| 136 Int64.ZERO); | |
| 137 expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ | 119 expect(new Int64.fromInts( 0x12345678, 0x12345678) ~/ |
| 138 new Int64.fromInts(0x0, 0x123), | 120 new Int64.fromInts(0x0, 0x123), |
| 139 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); | 121 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); |
| 140 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ | 122 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ |
| 141 new Int64.fromInts(0x1234, 0x12345678), | 123 new Int64.fromInts(0x1234, 0x12345678), |
| 142 new Int64.fromInts(0x0, 0x10003)); | 124 new Int64.fromInts(0x0, 0x10003)); |
| 143 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 125 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
| 144 new Int64.fromInts(0x1234, 0x12345678), | 126 new Int64.fromInts(0x1234, 0x12345678), |
| 145 new Int64.fromInts(0xffffffff, 0xffff3dfe)); | 127 new Int64.fromInts(0xffffffff, 0xffff3dfe)); |
| 146 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 128 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
| 147 new Int64.fromInts(0xffff1234, 0x12345678), | 129 new Int64.fromInts(0xffff1234, 0x12345678), |
| 148 new Int64.fromInts(0x0, 0xeda)); | 130 new Int64.fromInts(0x0, 0xeda)); |
| 149 expect(new Int64.fromInt(829893893) ~/ new Int32.fromInt(1919), | 131 expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); |
| 150 new Int32.fromInt(432461)); | 132 expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); |
| 151 expect(new Int64.fromInt(829893893) ~/ new Int64.fromInt(1919), | 133 expect(new Int64(829893893) ~/ 1919, new Int32(432461)); |
| 152 new Int32.fromInt(432461)); | 134 expect(() => new Int64(1) ~/ Int64.ZERO, |
| 153 expect(new Int64.fromInt(829893893) ~/ 1919, | |
| 154 new Int32.fromInt(432461)); | |
| 155 expect(() => new Int64.fromInt(1) ~/ Int64.ZERO, | |
| 156 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); | 135 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); |
| 157 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(2), | 136 expect(Int64.MIN_VALUE ~/ new Int64(2), |
| 158 new Int64.fromInts(0xc0000000, 0x00000000)); | 137 new Int64.fromInts(0xc0000000, 0x00000000)); |
| 159 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(1), Int64.MIN_VALUE); | 138 expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); |
| 160 expect(Int64.MIN_VALUE ~/ new Int64.fromInt(-1), Int64.MIN_VALUE); | 139 expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); |
| 161 expect(() => new Int64.fromInt(17) ~/ Int64.ZERO, throws); | 140 expect(() => new Int64(17) ~/ Int64.ZERO, throws); |
| 162 expect(() => new Int64.fromInt(17) ~/ null, throwsArgumentError); | 141 expect(() => new Int64(17) ~/ null, throwsArgumentError); |
| 163 }); | 142 }); |
| 164 | 143 |
| 165 test("%", () { | 144 test("%", () { |
| 166 // Define % as Euclidean mod, with positive result for all arguments | 145 // Define % as Euclidean mod, with positive result for all arguments |
| 167 expect(Int64.ZERO % new Int64.fromInt(1000), Int64.ZERO); | 146 expect(Int64.ZERO % new Int64(1000), Int64.ZERO); |
| 168 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); | 147 expect(Int64.MIN_VALUE % Int64.MIN_VALUE, Int64.ZERO); |
| 169 expect(new Int64.fromInt(1000) % Int64.MIN_VALUE, | 148 expect(new Int64(1000) % Int64.MIN_VALUE, new Int64(1000)); |
| 170 new Int64.fromInt(1000)); | 149 expect(Int64.MIN_VALUE % new Int64(8192), Int64.ZERO); |
| 171 expect(Int64.MIN_VALUE % new Int64.fromInt(8192), Int64.ZERO); | 150 expect(Int64.MIN_VALUE % new Int64(8193), new Int64(6145)); |
| 172 expect(Int64.MIN_VALUE % new Int64.fromInt(8193), | 151 expect(new Int64(-1000) % new Int64(8192), new Int64(7192)); |
| 173 new Int64.fromInt(6145)); | 152 expect(new Int64(-1000) % new Int64(8193), new Int64(7193)); |
| 174 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8192), | 153 expect(new Int64(-1000000000) % new Int64(8192), new Int64(5632)); |
| 175 new Int64.fromInt(7192)); | 154 expect(new Int64(-1000000000) % new Int64(8193), new Int64(4808)); |
| 176 expect(new Int64.fromInt(-1000) % new Int64.fromInt(8193), | 155 expect(new Int64(1000000000) % new Int64(8192), new Int64(2560)); |
| 177 new Int64.fromInt(7193)); | 156 expect(new Int64(1000000000) % new Int64(8193), new Int64(3385)); |
| 178 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8192), | |
| 179 new Int64.fromInt(5632)); | |
| 180 expect(new Int64.fromInt(-1000000000) % new Int64.fromInt(8193), | |
| 181 new Int64.fromInt(4808)); | |
| 182 expect(new Int64.fromInt(1000000000) % new Int64.fromInt(8192), | |
| 183 new Int64.fromInt(2560)); | |
| 184 expect(new Int64.fromInt(1000000000) % new Int64.fromInt(8193), | |
| 185 new Int64.fromInt(3385)); | |
| 186 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400), | 157 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00000400), |
| 187 new Int64.fromInts(0x0, 0x3ff)); | 158 new Int64.fromInts(0x0, 0x3ff)); |
| 188 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000), | 159 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x00040000), |
| 189 new Int64.fromInts(0x0, 0x3ffff)); | 160 new Int64.fromInts(0x0, 0x3ffff)); |
| 190 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000), | 161 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000000, 0x04000000), |
| 191 new Int64.fromInts(0x0, 0x3ffffff)); | 162 new Int64.fromInts(0x0, 0x3ffffff)); |
| 192 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000), | 163 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000004, 0x00000000), |
| 193 new Int64.fromInts(0x3, 0xffffffff)); | 164 new Int64.fromInts(0x3, 0xffffffff)); |
| 194 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000), | 165 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00000400, 0x00000000), |
| 195 new Int64.fromInts(0x3ff, 0xffffffff)); | 166 new Int64.fromInts(0x3ff, 0xffffffff)); |
| 196 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000), | 167 expect(Int64.MAX_VALUE % new Int64.fromInts(0x00040000, 0x00000000), |
| 197 new Int64.fromInts(0x3ffff, 0xffffffff)); | 168 new Int64.fromInts(0x3ffff, 0xffffffff)); |
| 198 expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000), | 169 expect(Int64.MAX_VALUE % new Int64.fromInts(0x04000000, 0x00000000), |
| 199 new Int64.fromInts(0x3ffffff, 0xffffffff)); | 170 new Int64.fromInts(0x3ffffff, 0xffffffff)); |
| 200 expect(new Int64.fromInt(0x12345678).remainder(new Int64.fromInt(0x22)), | 171 expect(new Int64(0x12345678).remainder(new Int64(0x22)), |
| 201 new Int64.fromInt(0x12345678.remainder(0x22))); | 172 new Int64(0x12345678.remainder(0x22))); |
| 202 expect(new Int64.fromInt(0x12345678).remainder(new Int64.fromInt(-0x22)), | 173 expect(new Int64(0x12345678).remainder(new Int64(-0x22)), |
| 203 new Int64.fromInt(0x12345678.remainder(-0x22))); | 174 new Int64(0x12345678.remainder(-0x22))); |
| 204 expect(new Int64.fromInt(-0x12345678).remainder(new Int64.fromInt(-0x22)), | 175 expect(new Int64(-0x12345678).remainder(new Int64(-0x22)), |
| 205 new Int64.fromInt(-0x12345678.remainder(-0x22))); | 176 new Int64(-0x12345678.remainder(-0x22))); |
| 206 expect(new Int64.fromInt(-0x12345678).remainder(new Int64.fromInt(0x22)), | 177 expect(new Int64(-0x12345678).remainder(new Int64(0x22)), |
| 207 new Int64.fromInt(-0x12345678.remainder(0x22))); | 178 new Int64(-0x12345678.remainder(0x22))); |
| 208 expect(new Int32.fromInt(0x12345678).remainder(new Int64.fromInt(0x22)), | 179 expect(new Int32(0x12345678).remainder(new Int64(0x22)), |
| 209 new Int64.fromInt(0x12345678.remainder(0x22))); | 180 new Int64(0x12345678.remainder(0x22))); |
| 210 }); | 181 }); |
| 211 }); | 182 }); |
| 212 | 183 |
| 213 group("comparison operators", () { | 184 group("comparison operators", () { |
| 214 Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0); | 185 Int64 largeNeg = new Int64.fromInts(0x82341234, 0x0); |
| 215 Int64 largePos = new Int64.fromInts(0x12341234, 0x0); | 186 Int64 largePos = new Int64.fromInts(0x12341234, 0x0); |
| 216 Int64 largePosPlusOne = largePos + new Int64.fromInt(1); | 187 Int64 largePosPlusOne = largePos + new Int64(1); |
| 217 | 188 |
| 218 test("<", () { | 189 test("<", () { |
| 219 expect(new Int64.fromInt(10) < new Int64.fromInt(11), true); | 190 expect(new Int64(10) < new Int64(11), true); |
| 220 expect(new Int64.fromInt(10) < new Int64.fromInt(10), false); | 191 expect(new Int64(10) < new Int64(10), false); |
| 221 expect(new Int64.fromInt(10) < new Int64.fromInt(9), false); | 192 expect(new Int64(10) < new Int64(9), false); |
| 222 expect(new Int64.fromInt(10) < new Int32.fromInt(11), true); | 193 expect(new Int64(10) < new Int32(11), true); |
| 223 expect(new Int64.fromInt(10) < new Int32.fromInt(10), false); | 194 expect(new Int64(10) < new Int32(10), false); |
| 224 expect(new Int64.fromInt(10) < new Int32.fromInt(9), false); | 195 expect(new Int64(10) < new Int32(9), false); |
| 225 expect(new Int64.fromInt(-10) < new Int64.fromInt(-11), false); | 196 expect(new Int64(-10) < new Int64(-11), false); |
| 226 expect(Int64.MIN_VALUE < Int64.ZERO, true); | 197 expect(Int64.MIN_VALUE < Int64.ZERO, true); |
| 227 expect(largeNeg < largePos, true); | 198 expect(largeNeg < largePos, true); |
| 228 expect(largePos < largePosPlusOne, true); | 199 expect(largePos < largePosPlusOne, true); |
| 229 expect(largePos < largePos, false); | 200 expect(largePos < largePos, false); |
| 230 expect(largePosPlusOne < largePos, false); | 201 expect(largePosPlusOne < largePos, false); |
| 231 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); | 202 expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true); |
| 232 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); | 203 expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false); |
| 233 expect(() => new Int64.fromInt(17) < null, throwsArgumentError); | 204 expect(() => new Int64(17) < null, throwsArgumentError); |
| 234 }); | 205 }); |
| 235 | 206 |
| 236 test("<=", () { | 207 test("<=", () { |
| 237 expect(new Int64.fromInt(10) <= new Int64.fromInt(11), true); | 208 expect(new Int64(10) <= new Int64(11), true); |
| 238 expect(new Int64.fromInt(10) <= new Int64.fromInt(10), true); | 209 expect(new Int64(10) <= new Int64(10), true); |
| 239 expect(new Int64.fromInt(10) <= new Int64.fromInt(9), false); | 210 expect(new Int64(10) <= new Int64(9), false); |
| 240 expect(new Int64.fromInt(10) <= new Int32.fromInt(11), true); | 211 expect(new Int64(10) <= new Int32(11), true); |
| 241 expect(new Int64.fromInt(10) <= new Int32.fromInt(10), true); | 212 expect(new Int64(10) <= new Int32(10), true); |
| 242 expect(new Int64.fromInt(10) <= new Int64.fromInt(9), false); | 213 expect(new Int64(10) <= new Int64(9), false); |
| 243 expect(new Int64.fromInt(-10) <= new Int64.fromInt(-11), false); | 214 expect(new Int64(-10) <= new Int64(-11), false); |
| 244 expect(new Int64.fromInt(-10) <= new Int64.fromInt(-10), true); | 215 expect(new Int64(-10) <= new Int64(-10), true); |
| 245 expect(largeNeg <= largePos, true); | 216 expect(largeNeg <= largePos, true); |
| 246 expect(largePos <= largeNeg, false); | 217 expect(largePos <= largeNeg, false); |
| 247 expect(largePos <= largePosPlusOne, true); | 218 expect(largePos <= largePosPlusOne, true); |
| 248 expect(largePos <= largePos, true); | 219 expect(largePos <= largePos, true); |
| 249 expect(largePosPlusOne <= largePos, false); | 220 expect(largePosPlusOne <= largePos, false); |
| 250 expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); | 221 expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true); |
| 251 expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); | 222 expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false); |
| 252 expect(() => new Int64.fromInt(17) <= null, throwsArgumentError); | 223 expect(() => new Int64(17) <= null, throwsArgumentError); |
| 253 }); | 224 }); |
| 254 | 225 |
| 255 test("==", () { | 226 test("==", () { |
| 256 expect(new Int64.fromInt(10) == new Int64.fromInt(11), false); | 227 expect(new Int64(10) == new Int64(11), false); |
| 257 expect(new Int64.fromInt(10) == new Int64.fromInt(10), true); | 228 expect(new Int64(10) == new Int64(10), true); |
| 258 expect(new Int64.fromInt(10) == new Int64.fromInt(9), false); | 229 expect(new Int64(10) == new Int64(9), false); |
| 259 expect(new Int64.fromInt(10) == new Int32.fromInt(11), false); | 230 expect(new Int64(10) == new Int32(11), false); |
| 260 expect(new Int64.fromInt(10) == new Int32.fromInt(10), true); | 231 expect(new Int64(10) == new Int32(10), true); |
| 261 expect(new Int64.fromInt(10) == new Int32.fromInt(9), false); | 232 expect(new Int64(10) == new Int32(9), false); |
| 262 expect(new Int64.fromInt(-10) == new Int64.fromInt(-10), true); | 233 expect(new Int64(-10) == new Int64(-10), true); |
| 263 expect(new Int64.fromInt(-10) != new Int64.fromInt(-10), false); | 234 expect(new Int64(-10) != new Int64(-10), false); |
| 264 expect(largePos == largePos, true); | 235 expect(largePos == largePos, true); |
| 265 expect(largePos == largePosPlusOne, false); | 236 expect(largePos == largePosPlusOne, false); |
| 266 expect(largePosPlusOne == largePos, false); | 237 expect(largePosPlusOne == largePos, false); |
| 267 expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false); | 238 expect(Int64.MIN_VALUE == Int64.MAX_VALUE, false); |
| 268 expect(new Int64.fromInt(17) == new Object(), false); | 239 expect(new Int64(17) == new Object(), false); |
| 269 expect(new Int64.fromInt(17) == null, false); | 240 expect(new Int64(17) == null, false); |
| 270 }); | 241 }); |
| 271 | 242 |
| 272 test(">=", () { | 243 test(">=", () { |
| 273 expect(new Int64.fromInt(10) >= new Int64.fromInt(11), false); | 244 expect(new Int64(10) >= new Int64(11), false); |
| 274 expect(new Int64.fromInt(10) >= new Int64.fromInt(10), true); | 245 expect(new Int64(10) >= new Int64(10), true); |
| 275 expect(new Int64.fromInt(10) >= new Int64.fromInt(9), true); | 246 expect(new Int64(10) >= new Int64(9), true); |
| 276 expect(new Int64.fromInt(10) >= new Int32.fromInt(11), false); | 247 expect(new Int64(10) >= new Int32(11), false); |
| 277 expect(new Int64.fromInt(10) >= new Int32.fromInt(10), true); | 248 expect(new Int64(10) >= new Int32(10), true); |
| 278 expect(new Int64.fromInt(10) >= new Int32.fromInt(9), true); | 249 expect(new Int64(10) >= new Int32(9), true); |
| 279 expect(new Int64.fromInt(-10) >= new Int64.fromInt(-11), true); | 250 expect(new Int64(-10) >= new Int64(-11), true); |
| 280 expect(new Int64.fromInt(-10) >= new Int64.fromInt(-10), true); | 251 expect(new Int64(-10) >= new Int64(-10), true); |
| 281 expect(largePos >= largeNeg, true); | 252 expect(largePos >= largeNeg, true); |
| 282 expect(largeNeg >= largePos, false); | 253 expect(largeNeg >= largePos, false); |
| 283 expect(largePos >= largePosPlusOne, false); | 254 expect(largePos >= largePosPlusOne, false); |
| 284 expect(largePos >= largePos, true); | 255 expect(largePos >= largePos, true); |
| 285 expect(largePosPlusOne >= largePos, true); | 256 expect(largePosPlusOne >= largePos, true); |
| 286 expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); | 257 expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false); |
| 287 expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); | 258 expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true); |
| 288 expect(() => new Int64.fromInt(17) >= null, throwsArgumentError); | 259 expect(() => new Int64(17) >= null, throwsArgumentError); |
| 289 }); | 260 }); |
| 290 | 261 |
| 291 test(">", () { | 262 test(">", () { |
| 292 expect(new Int64.fromInt(10) > new Int64.fromInt(11), false); | 263 expect(new Int64(10) > new Int64(11), false); |
| 293 expect(new Int64.fromInt(10) > new Int64.fromInt(10), false); | 264 expect(new Int64(10) > new Int64(10), false); |
| 294 expect(new Int64.fromInt(10) > new Int64.fromInt(9), true); | 265 expect(new Int64(10) > new Int64(9), true); |
| 295 expect(new Int64.fromInt(10) > new Int32.fromInt(11), false); | 266 expect(new Int64(10) > new Int32(11), false); |
| 296 expect(new Int64.fromInt(10) > new Int32.fromInt(10), false); | 267 expect(new Int64(10) > new Int32(10), false); |
| 297 expect(new Int64.fromInt(10) > new Int32.fromInt(9), true); | 268 expect(new Int64(10) > new Int32(9), true); |
| 298 expect(new Int64.fromInt(-10) > new Int64.fromInt(-11), true); | 269 expect(new Int64(-10) > new Int64(-11), true); |
| 299 expect(new Int64.fromInt(10) > new Int64.fromInt(-11), true); | 270 expect(new Int64(10) > new Int64(-11), true); |
| 300 expect(new Int64.fromInt(-10) > new Int64.fromInt(11), false); | 271 expect(new Int64(-10) > new Int64(11), false); |
| 301 expect(largePos > largeNeg, true); | 272 expect(largePos > largeNeg, true); |
| 302 expect(largeNeg > largePos, false); | 273 expect(largeNeg > largePos, false); |
| 303 expect(largePos > largePosPlusOne, false); | 274 expect(largePos > largePosPlusOne, false); |
| 304 expect(largePos > largePos, false); | 275 expect(largePos > largePos, false); |
| 305 expect(largePosPlusOne > largePos, true); | 276 expect(largePosPlusOne > largePos, true); |
| 306 expect(Int64.ZERO > Int64.MIN_VALUE, true); | 277 expect(Int64.ZERO > Int64.MIN_VALUE, true); |
| 307 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); | 278 expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false); |
| 308 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); | 279 expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true); |
| 309 expect(() => new Int64.fromInt(17) > null, throwsArgumentError); | 280 expect(() => new Int64(17) > null, throwsArgumentError); |
| 310 }); | 281 }); |
| 311 }); | 282 }); |
| 312 | 283 |
| 313 group("bitwise operators", () { | 284 group("bitwise operators", () { |
| 314 Int64 n1 = new Int64.fromInt(1234); | 285 Int64 n1 = new Int64(1234); |
| 315 Int64 n2 = new Int64.fromInt(9876); | 286 Int64 n2 = new Int64(9876); |
| 316 Int64 n3 = new Int64.fromInt(-1234); | 287 Int64 n3 = new Int64(-1234); |
| 317 Int64 n4 = new Int64.fromInt(0x1234) << 32; | 288 Int64 n4 = new Int64(0x1234) << 32; |
| 318 Int64 n5 = new Int64.fromInt(0x9876) << 32; | 289 Int64 n5 = new Int64(0x9876) << 32; |
| 319 | 290 |
| 320 test("&", () { | 291 test("&", () { |
| 321 expect(n1 & n2, new Int64.fromInt(1168)); | 292 expect(n1 & n2, new Int64(1168)); |
| 322 expect(n3 & n2, new Int64.fromInt(8708)); | 293 expect(n3 & n2, new Int64(8708)); |
| 323 expect(n4 & n5, new Int64.fromInt(0x1034) << 32); | 294 expect(n4 & n5, new Int64(0x1034) << 32); |
| 324 expect(() => n1 & null, throwsArgumentError); | 295 expect(() => n1 & null, throwsArgumentError); |
| 325 }); | 296 }); |
| 326 | 297 |
| 327 test("|", () { | 298 test("|", () { |
| 328 expect(n1 | n2, new Int64.fromInt(9942)); | 299 expect(n1 | n2, new Int64(9942)); |
| 329 expect(n3 | n2, new Int64.fromInt(-66)); | 300 expect(n3 | n2, new Int64(-66)); |
| 330 expect(n4 | n5, new Int64.fromInt(0x9a76) << 32); | 301 expect(n4 | n5, new Int64(0x9a76) << 32); |
| 331 expect(() => n1 | null, throwsArgumentError); | 302 expect(() => n1 | null, throwsArgumentError); |
| 332 }); | 303 }); |
| 333 | 304 |
| 334 test("^", () { | 305 test("^", () { |
| 335 expect(n1 ^ n2, new Int64.fromInt(8774)); | 306 expect(n1 ^ n2, new Int64(8774)); |
| 336 expect(n3 ^ n2, new Int64.fromInt(-8774)); | 307 expect(n3 ^ n2, new Int64(-8774)); |
| 337 expect(n4 ^ n5, new Int64.fromInt(0x8a42) << 32); | 308 expect(n4 ^ n5, new Int64(0x8a42) << 32); |
| 338 expect(() => n1 ^ null, throwsArgumentError); | 309 expect(() => n1 ^ null, throwsArgumentError); |
| 339 }); | 310 }); |
| 340 | 311 |
| 341 test("~", () { | 312 test("~", () { |
| 342 expect(-new Int64.fromInt(1), new Int64.fromInt(-1)); | 313 expect(-new Int64(1), new Int64(-1)); |
| 343 expect(-new Int64.fromInt(-1), new Int64.fromInt(1)); | 314 expect(-new Int64(-1), new Int64(1)); |
| 344 expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); | 315 expect(-Int64.MIN_VALUE, Int64.MIN_VALUE); |
| 345 | 316 |
| 346 expect(~n1, new Int64.fromInt(-1235)); | 317 expect(~n1, new Int64(-1235)); |
| 347 expect(~n2, new Int64.fromInt(-9877)); | 318 expect(~n2, new Int64(-9877)); |
| 348 expect(~n3, new Int64.fromInt(1233)); | 319 expect(~n3, new Int64(1233)); |
| 349 expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff)); | 320 expect(~n4, new Int64.fromInts(0xffffedcb, 0xffffffff)); |
| 350 expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff)); | 321 expect(~n5, new Int64.fromInts(0xffff6789, 0xffffffff)); |
| 351 }); | 322 }); |
| 352 }); | 323 }); |
| 353 | 324 |
| 354 group("bitshift operators", () { | 325 group("bitshift operators", () { |
| 355 test("<<", () { | 326 test("<<", () { |
| 356 expect(new Int64.fromInts(0x12341234, 0x45674567) << 10, | 327 expect(new Int64.fromInts(0x12341234, 0x45674567) << 10, |
| 357 new Int64.fromInts(0xd048d115, 0x9d159c00)); | 328 new Int64.fromInts(0xd048d115, 0x9d159c00)); |
| 358 expect(new Int64.fromInts(0x92341234, 0x45674567) << 10, | 329 expect(new Int64.fromInts(0x92341234, 0x45674567) << 10, |
| 359 new Int64.fromInts(0xd048d115, 0x9d159c00)); | 330 new Int64.fromInts(0xd048d115, 0x9d159c00)); |
| 360 expect(new Int64.fromInt(-1) << 5, new Int64.fromInt(-32)); | 331 expect(new Int64(-1) << 5, new Int64(-32)); |
| 361 expect(new Int64.fromInt(-1) << 0, new Int64.fromInt(-1)); | 332 expect(new Int64(-1) << 0, new Int64(-1)); |
| 362 expect(() => new Int64.fromInt(17) << -1, throwsArgumentError); | 333 expect(() => new Int64(17) << -1, throwsArgumentError); |
| 363 expect(() => new Int64.fromInt(17) << null, throws); | 334 expect(() => new Int64(17) << null, throws); |
| 364 }); | 335 }); |
| 365 | 336 |
| 366 test(">>", () { | 337 test(">>", () { |
| 367 expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624"); | 338 expect((Int64.MIN_VALUE >> 13).toString(), "-1125899906842624"); |
| 368 expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10, | 339 expect(new Int64.fromInts(0x12341234, 0x45674567) >> 10, |
| 369 new Int64.fromInts(0x48d04, 0x8d1159d1)); | 340 new Int64.fromInts(0x48d04, 0x8d1159d1)); |
| 370 expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10, | 341 expect(new Int64.fromInts(0x92341234, 0x45674567) >> 10, |
| 371 new Int64.fromInts(0xffe48d04, 0x8d1159d1)); | 342 new Int64.fromInts(0xffe48d04, 0x8d1159d1)); |
| 372 expect(new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, | 343 expect(new Int64.fromInts(0xFFFFFFF, 0xFFFFFFFF) >> 34, |
| 373 new Int64.fromInt(67108863)); | 344 new Int64(67108863)); |
| 374 for (int n = 0; n <= 66; n++) { | 345 for (int n = 0; n <= 66; n++) { |
| 375 expect(new Int64.fromInt(-1) >> n, new Int64.fromInt(-1)); | 346 expect(new Int64(-1) >> n, new Int64(-1)); |
| 376 } | 347 } |
| 377 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8, | 348 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 8, |
| 378 new Int64.fromInts(0x00723456, 0x789abcde)); | 349 new Int64.fromInts(0x00723456, 0x789abcde)); |
| 379 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16, | 350 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 16, |
| 380 new Int64.fromInts(0x00007234, 0x56789abc)); | 351 new Int64.fromInts(0x00007234, 0x56789abc)); |
| 381 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24, | 352 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 24, |
| 382 new Int64.fromInts(0x00000072, 0x3456789a)); | 353 new Int64.fromInts(0x00000072, 0x3456789a)); |
| 383 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28, | 354 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 28, |
| 384 new Int64.fromInts(0x00000007, 0x23456789)); | 355 new Int64.fromInts(0x00000007, 0x23456789)); |
| 385 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32, | 356 expect(new Int64.fromInts(0x72345678, 0x9abcdef0) >> 32, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32, | 374 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 32, |
| 404 new Int64.fromInts(0xffffffff, 0x92345678)); | 375 new Int64.fromInts(0xffffffff, 0x92345678)); |
| 405 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36, | 376 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 36, |
| 406 new Int64.fromInts(0xffffffff, 0xf9234567)); | 377 new Int64.fromInts(0xffffffff, 0xf9234567)); |
| 407 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40, | 378 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 40, |
| 408 new Int64.fromInts(0xffffffff, 0xff923456)); | 379 new Int64.fromInts(0xffffffff, 0xff923456)); |
| 409 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44, | 380 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 44, |
| 410 new Int64.fromInts(0xffffffff, 0xfff92345)); | 381 new Int64.fromInts(0xffffffff, 0xfff92345)); |
| 411 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, | 382 expect(new Int64.fromInts(0x92345678, 0x9abcdef0) >> 48, |
| 412 new Int64.fromInts(0xffffffff, 0xffff9234)); | 383 new Int64.fromInts(0xffffffff, 0xffff9234)); |
| 413 expect(() => new Int64.fromInt(17) >> -1, throwsArgumentError); | 384 expect(() => new Int64(17) >> -1, throwsArgumentError); |
| 414 expect(() => new Int64.fromInt(17) >> null, throws); | 385 expect(() => new Int64(17) >> null, throws); |
| 415 }); | 386 }); |
| 416 | 387 |
| 417 test("shiftRightUnsigned", () { | 388 test("shiftRightUnsigned", () { |
| 418 expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), | 389 expect(new Int64.fromInts(0x12341234, 0x45674567).shiftRightUnsigned(10), |
| 419 new Int64.fromInts(0x48d04, 0x8d1159d1)); | 390 new Int64.fromInts(0x48d04, 0x8d1159d1)); |
| 420 expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), | 391 expect(new Int64.fromInts(0x92341234, 0x45674567).shiftRightUnsigned(10), |
| 421 new Int64.fromInts(0x248d04, 0x8d1159d1)); | 392 new Int64.fromInts(0x248d04, 0x8d1159d1)); |
| 422 expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8), | 393 expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(8), |
| 423 new Int64.fromInts(0x00723456, 0x789abcde)); | 394 new Int64.fromInts(0x00723456, 0x789abcde)); |
| 424 expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16), | 395 expect(new Int64.fromInts(0x72345678, 0x9abcdef0).shiftRightUnsigned(16), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 448 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32), | 419 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(32), |
| 449 new Int64.fromInts(0x00000000, 0x92345678)); | 420 new Int64.fromInts(0x00000000, 0x92345678)); |
| 450 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36), | 421 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(36), |
| 451 new Int64.fromInts(0x00000000, 0x09234567)); | 422 new Int64.fromInts(0x00000000, 0x09234567)); |
| 452 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40), | 423 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(40), |
| 453 new Int64.fromInts(0x00000000, 0x00923456)); | 424 new Int64.fromInts(0x00000000, 0x00923456)); |
| 454 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44), | 425 expect(new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(44), |
| 455 new Int64.fromInts(0x00000000, 0x00092345)); | 426 new Int64.fromInts(0x00000000, 0x00092345)); |
| 456 expect(new Int64.fromInts(0x00000000, 0x00009234), | 427 expect(new Int64.fromInts(0x00000000, 0x00009234), |
| 457 new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); | 428 new Int64.fromInts(0x92345678, 0x9abcdef0).shiftRightUnsigned(48)); |
| 458 expect(() => new Int64.fromInt(17).shiftRightUnsigned(-1), | 429 expect(() => new Int64(17).shiftRightUnsigned(-1), |
| 459 throwsArgumentError); | 430 throwsArgumentError); |
| 460 expect(() => new Int64.fromInt(17).shiftRightUnsigned(null), throws); | 431 expect(() => new Int64(17).shiftRightUnsigned(null), throws); |
| 461 }); | 432 }); |
| 462 | 433 |
| 463 test("overflow", () { | 434 test("overflow", () { |
| 464 expect((new Int64.fromInt(1) << 63) >> 1, | 435 expect((new Int64(1) << 63) >> 1, |
| 465 -new Int64.fromInts(0x40000000, 0x00000000)); | 436 -new Int64.fromInts(0x40000000, 0x00000000)); |
| 466 expect((new Int64.fromInt(-1) << 32) << 32, new Int64.fromInt(0)); | 437 expect((new Int64(-1) << 32) << 32, new Int64(0)); |
| 467 expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE); | 438 expect(Int64.MIN_VALUE << 0, Int64.MIN_VALUE); |
| 468 expect(Int64.MIN_VALUE << 1, new Int64.fromInt(0)); | 439 expect(Int64.MIN_VALUE << 1, new Int64(0)); |
| 469 expect((-new Int64.fromInts(8, 0)) >> 1, | 440 expect((-new Int64.fromInts(8, 0)) >> 1, |
| 470 new Int64.fromInts(0xfffffffc, 0x00000000)); | 441 new Int64.fromInts(0xfffffffc, 0x00000000)); |
| 471 expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1), | 442 expect((-new Int64.fromInts(8, 0)).shiftRightUnsigned(1), |
| 472 new Int64.fromInts(0x7ffffffc, 0x0)); | 443 new Int64.fromInts(0x7ffffffc, 0x0)); |
| 473 }); | 444 }); |
| 474 }); | 445 }); |
| 475 | 446 |
| 476 group("type conversions", () { | 447 group("type conversions", () { |
| 477 test("toInt", () { | 448 test("toInt", () { |
| 478 expect(new Int64.fromInt(0).toInt(), 0); | 449 expect(new Int64(0).toInt(), 0); |
| 479 expect(new Int64.fromInt(100).toInt(), 100); | 450 expect(new Int64(100).toInt(), 100); |
| 480 expect(new Int64.fromInt(-100).toInt(), -100); | 451 expect(new Int64(-100).toInt(), -100); |
| 481 expect(new Int64.fromInt(2147483647).toInt(), 2147483647); | 452 expect(new Int64(2147483647).toInt(), 2147483647); |
| 482 expect(new Int64.fromInt(2147483648).toInt(), 2147483648); | 453 expect(new Int64(2147483648).toInt(), 2147483648); |
| 483 expect(new Int64.fromInt(-2147483647).toInt(), -2147483647); | 454 expect(new Int64(-2147483647).toInt(), -2147483647); |
| 484 expect(new Int64.fromInt(-2147483648).toInt(), -2147483648); | 455 expect(new Int64(-2147483648).toInt(), -2147483648); |
| 485 expect(new Int64.fromInt(4503599627370495).toInt(), 4503599627370495); | 456 expect(new Int64(4503599627370495).toInt(), 4503599627370495); |
| 486 expect(new Int64.fromInt(4503599627370496).toInt(), 4503599627370496); | 457 expect(new Int64(4503599627370496).toInt(), 4503599627370496); |
| 487 expect(new Int64.fromInt(-4503599627370495).toInt(), -4503599627370495); | 458 expect(new Int64(-4503599627370495).toInt(), -4503599627370495); |
| 488 expect(new Int64.fromInt(-4503599627370496).toInt(), -4503599627370496); | 459 expect(new Int64(-4503599627370496).toInt(), -4503599627370496); |
| 489 }); | 460 }); |
| 490 | 461 |
| 491 test("toInt32", () { | 462 test("toInt32", () { |
| 492 expect(new Int64.fromInt(0).toInt32(), new Int32.fromInt(0)); | 463 expect(new Int64(0).toInt32(), new Int32(0)); |
| 493 expect(new Int64.fromInt(1).toInt32(), new Int32.fromInt(1)); | 464 expect(new Int64(1).toInt32(), new Int32(1)); |
| 494 expect(new Int64.fromInt(-1).toInt32(), new Int32.fromInt(-1)); | 465 expect(new Int64(-1).toInt32(), new Int32(-1)); |
| 495 expect(new Int64.fromInt(2147483647).toInt32(), | 466 expect(new Int64(2147483647).toInt32(), new Int32(2147483647)); |
| 496 new Int32.fromInt(2147483647)); | 467 expect(new Int64(2147483648).toInt32(), new Int32(-2147483648)); |
| 497 expect(new Int64.fromInt(2147483648).toInt32(), | 468 expect(new Int64(2147483649).toInt32(), new Int32(-2147483647)); |
| 498 new Int32.fromInt(-2147483648)); | 469 expect(new Int64(2147483650).toInt32(), new Int32(-2147483646)); |
| 499 expect(new Int64.fromInt(2147483649).toInt32(), | 470 expect(new Int64(-2147483648).toInt32(), new Int32(-2147483648)); |
| 500 new Int32.fromInt(-2147483647)); | 471 expect(new Int64(-2147483649).toInt32(), new Int32(2147483647)); |
| 501 expect(new Int64.fromInt(2147483650).toInt32(), | 472 expect(new Int64(-2147483650).toInt32(), new Int32(2147483646)); |
| 502 new Int32.fromInt(-2147483646)); | 473 expect(new Int64(-2147483651).toInt32(), new Int32(2147483645)); |
| 503 expect(new Int64.fromInt(-2147483648).toInt32(), | |
| 504 new Int32.fromInt(-2147483648)); | |
| 505 expect(new Int64.fromInt(-2147483649).toInt32(), | |
| 506 new Int32.fromInt(2147483647)); | |
| 507 expect(new Int64.fromInt(-2147483650).toInt32(), | |
| 508 new Int32.fromInt(2147483646)); | |
| 509 expect(new Int64.fromInt(-2147483651).toInt32(), | |
| 510 new Int32.fromInt(2147483645)); | |
| 511 }); | 474 }); |
| 512 }); | 475 }); |
| 513 | 476 |
| 514 test("JavaScript 53-bit integer boundary", () { | 477 test("JavaScript 53-bit integer boundary", () { |
| 515 Int64 _factorial(Int64 n) { | 478 Int64 _factorial(Int64 n) { |
| 516 if (n.isZero) { | 479 if (n.isZero) { |
| 517 return new Int64.fromInt(1); | 480 return new Int64(1); |
| 518 } else { | 481 } else { |
| 519 return n * _factorial(n - new Int64.fromInt(1)); | 482 return n * _factorial(n - new Int64(1)); |
| 520 } | 483 } |
| 521 } | 484 } |
| 522 Int64 fact18 = _factorial(new Int64.fromInt(18)); | 485 Int64 fact18 = _factorial(new Int64(18)); |
| 523 Int64 fact17 = _factorial(new Int64.fromInt(17)); | 486 Int64 fact17 = _factorial(new Int64(17)); |
| 524 expect(fact18 ~/ fact17, new Int64.fromInt(18)); | 487 expect(fact18 ~/ fact17, new Int64(18)); |
| 525 }); | 488 }); |
| 526 | 489 |
| 527 test("min, max values", () { | 490 test("min, max values", () { |
| 528 expect(new Int64.fromInt(1) << 63, Int64.MIN_VALUE); | 491 expect(new Int64(1) << 63, Int64.MIN_VALUE); |
| 529 expect(-(Int64.MIN_VALUE + new Int64.fromInt(1)), Int64.MAX_VALUE); | 492 expect(-(Int64.MIN_VALUE + new Int64(1)), Int64.MAX_VALUE); |
| 530 }); | 493 }); |
| 531 | 494 |
| 532 group("parse", () { | 495 group("parse", () { |
| 533 test("parseRadix10", () { | 496 test("parseRadix10", () { |
| 534 checkInt(int x) { | 497 checkInt(int x) { |
| 535 expect(Int64.parseRadix('$x', 10), new Int64.fromInt(x)); | 498 expect(Int64.parseRadix('$x', 10), new Int64(x)); |
| 536 } | 499 } |
| 537 checkInt(0); | 500 checkInt(0); |
| 538 checkInt(1); | 501 checkInt(1); |
| 539 checkInt(-1); | 502 checkInt(-1); |
| 540 checkInt(1000); | 503 checkInt(1000); |
| 541 checkInt(12345678); | 504 checkInt(12345678); |
| 542 checkInt(-12345678); | 505 checkInt(-12345678); |
| 543 checkInt(2147483647); | 506 checkInt(2147483647); |
| 544 checkInt(2147483648); | 507 checkInt(2147483648); |
| 545 checkInt(-2147483647); | 508 checkInt(-2147483647); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 566 test("parseRadixN", () { | 529 test("parseRadixN", () { |
| 567 check(String s, int r) { | 530 check(String s, int r) { |
| 568 expect(Int64.parseRadix(s, r).toRadixString(r), s); | 531 expect(Int64.parseRadix(s, r).toRadixString(r), s); |
| 569 } | 532 } |
| 570 check("2ppp111222333", 33); // This value & radix requires three chunks. | 533 check("2ppp111222333", 33); // This value & radix requires three chunks. |
| 571 }); | 534 }); |
| 572 }); | 535 }); |
| 573 | 536 |
| 574 group("string representation", () { | 537 group("string representation", () { |
| 575 test("toString", () { | 538 test("toString", () { |
| 576 expect(new Int64.fromInt(0).toString(), "0"); | 539 expect(new Int64(0).toString(), "0"); |
| 577 expect(new Int64.fromInt(1).toString(), "1"); | 540 expect(new Int64(1).toString(), "1"); |
| 578 expect(new Int64.fromInt(-1).toString(), "-1"); | 541 expect(new Int64(-1).toString(), "-1"); |
| 579 expect(new Int64.fromInt(-10).toString(), "-10"); | 542 expect(new Int64(-10).toString(), "-10"); |
| 580 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); | 543 expect(Int64.MIN_VALUE.toString(), "-9223372036854775808"); |
| 581 expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); | 544 expect(Int64.MAX_VALUE.toString(), "9223372036854775807"); |
| 582 | 545 |
| 583 int top = 922337201; | 546 int top = 922337201; |
| 584 int bottom = 967490662; | 547 int bottom = 967490662; |
| 585 Int64 fullnum = (new Int64.fromInt(1000000000) * new Int64.fromInt(top)) + | 548 Int64 fullnum = (new Int64(1000000000) * new Int64(top)) + |
| 586 new Int64.fromInt(bottom); | 549 new Int64(bottom); |
| 587 expect(fullnum.toString(), "922337201967490662"); | 550 expect(fullnum.toString(), "922337201967490662"); |
| 588 expect((-fullnum).toString(), "-922337201967490662"); | 551 expect((-fullnum).toString(), "-922337201967490662"); |
| 589 expect(new Int64.fromInt(123456789).toString(), "123456789"); | 552 expect(new Int64(123456789).toString(), "123456789"); |
| 590 }); | 553 }); |
| 591 | 554 |
| 592 test("toHexString", () { | 555 test("toHexString", () { |
| 593 Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234); | 556 Int64 deadbeef12341234 = new Int64.fromInts(0xDEADBEEF, 0x12341234); |
| 594 expect(Int64.ZERO.toHexString(), "0"); | 557 expect(Int64.ZERO.toHexString(), "0"); |
| 595 expect(deadbeef12341234.toHexString(), "DEADBEEF12341234"); | 558 expect(deadbeef12341234.toHexString(), "DEADBEEF12341234"); |
| 596 expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), | 559 expect(new Int64.fromInts(0x17678A7, 0xDEF01234).toHexString(), |
| 597 "17678A7DEF01234"); | 560 "17678A7DEF01234"); |
| 598 expect(new Int64.fromInt(123456789).toHexString(), "75BCD15"); | 561 expect(new Int64(123456789).toHexString(), "75BCD15"); |
| 599 }); | 562 }); |
| 600 | 563 |
| 601 test("toRadixString", () { | 564 test("toRadixString", () { |
| 602 expect(new Int64.fromInt(123456789).toRadixString(5), "223101104124"); | 565 expect(new Int64(123456789).toRadixString(5), "223101104124"); |
| 603 expect(Int64.MIN_VALUE.toRadixString(2), | 566 expect(Int64.MIN_VALUE.toRadixString(2), |
| 604 "-1000000000000000000000000000000000000000000000000000000000000000"); | 567 "-1000000000000000000000000000000000000000000000000000000000000000"); |
| 605 expect(Int64.MIN_VALUE.toRadixString(3), | 568 expect(Int64.MIN_VALUE.toRadixString(3), |
| 606 "-2021110011022210012102010021220101220222"); | 569 "-2021110011022210012102010021220101220222"); |
| 607 expect(Int64.MIN_VALUE.toRadixString(4), | 570 expect(Int64.MIN_VALUE.toRadixString(4), |
| 608 "-20000000000000000000000000000000"); | 571 "-20000000000000000000000000000000"); |
| 609 expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); | 572 expect(Int64.MIN_VALUE.toRadixString(5), "-1104332401304422434310311213"); |
| 610 expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); | 573 expect(Int64.MIN_VALUE.toRadixString(6), "-1540241003031030222122212"); |
| 611 expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); | 574 expect(Int64.MIN_VALUE.toRadixString(7), "-22341010611245052052301"); |
| 612 expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); | 575 expect(Int64.MIN_VALUE.toRadixString(8), "-1000000000000000000000"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 632 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); | 595 expect(Int64.MAX_VALUE.toRadixString(10), "9223372036854775807"); |
| 633 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); | 596 expect(Int64.MAX_VALUE.toRadixString(11), "1728002635214590697"); |
| 634 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); | 597 expect(Int64.MAX_VALUE.toRadixString(12), "41a792678515120367"); |
| 635 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); | 598 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); |
| 636 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); | 599 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); |
| 637 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); | 600 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); |
| 638 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); | 601 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); |
| 639 }); | 602 }); |
| 640 }); | 603 }); |
| 641 } | 604 } |
| OLD | NEW |