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:test/test.dart'; |
9 | 9 |
10 void main() { | 10 void main() { |
11 group("fromBytes", () { | 11 group("fromBytes", () { |
12 test("fromBytes", () { | 12 test("fromBytes", () { |
13 checkBytes(List<int> bytes, int h, int l) { | 13 checkBytes(List<int> bytes, int h, int l) { |
14 expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l)); | 14 expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l)); |
15 } | 15 } |
16 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); | 16 checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0); |
17 checkBytes([ 1, 0, 0, 0, 0, 0, 0, 0 ], 0, 1); | 17 checkBytes([ 1, 0, 0, 0, 0, 0, 0, 0 ], 0, 1); |
18 checkBytes([ 1, 2, 3, 4, 5, 6, 7, 8 ], 0x08070605, 0x04030201); | 18 checkBytes([ 1, 2, 3, 4, 5, 6, 7, 8 ], 0x08070605, 0x04030201); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 }); | 122 }); |
123 | 123 |
124 test("*", () { | 124 test("*", () { |
125 expect(new Int64(1111) * new Int64(3), new Int64(3333)); | 125 expect(new Int64(1111) * new Int64(3), new Int64(3333)); |
126 expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); | 126 expect(new Int64(1111) * new Int64(-3), new Int64(-3333)); |
127 expect(new Int64(-1111) * new Int64(3), new Int64(-3333)); | 127 expect(new Int64(-1111) * new Int64(3), new Int64(-3333)); |
128 expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); | 128 expect(new Int64(-1111) * new Int64(-3), new Int64(3333)); |
129 expect(new Int64(100) * Int64.ZERO, Int64.ZERO); | 129 expect(new Int64(100) * Int64.ZERO, Int64.ZERO); |
130 | 130 |
131 expect(new Int64.fromInts(0x12345678, 0x12345678) * | 131 expect(new Int64.fromInts(0x12345678, 0x12345678) * |
132 new Int64.fromInts(0x1234, 0x12345678), | 132 new Int64.fromInts(0x1234, 0x12345678), |
133 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 133 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
134 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 134 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
135 new Int64.fromInts(0x1234, 0x12345678), | 135 new Int64.fromInts(0x1234, 0x12345678), |
136 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); | 136 new Int64.fromInts(0x7ff63f7c, 0x1df4d840)); |
137 expect(new Int64.fromInts(0xf2345678, 0x12345678) * | 137 expect(new Int64.fromInts(0xf2345678, 0x12345678) * |
138 new Int64.fromInts(0xffff1234, 0x12345678), | 138 new Int64.fromInts(0xffff1234, 0x12345678), |
139 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); | 139 new Int64.fromInts(0x297e3f7c, 0x1df4d840)); |
140 | 140 |
141 // RHS Int32 | 141 // RHS Int32 |
142 expect((new Int64(123456789) * new Int32(987654321)), | 142 expect((new Int64(123456789) * new Int32(987654321)), |
143 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 143 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
144 expect((new Int64(123456789) * new Int32(987654321)), | 144 expect((new Int64(123456789) * new Int32(987654321)), |
145 new Int64.fromInts(0x1b13114, 0xfbff5385)); | 145 new Int64.fromInts(0x1b13114, 0xfbff5385)); |
146 | 146 |
147 // Wraparound | 147 // Wraparound |
148 expect((new Int64(123456789) * new Int64(987654321)), | 148 expect((new Int64(123456789) * new Int64(987654321)), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 expect(Int64.MAX_VALUE ~/ new Int64(0x123456), | 196 expect(Int64.MAX_VALUE ~/ new Int64(0x123456), |
197 new Int64.fromInts(0x708, 0x002E9501)); | 197 new Int64.fromInts(0x708, 0x002E9501)); |
198 expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9)); | 198 expect(Int64.MAX_VALUE % new Int64(0x123456), new Int64(0x3BDA9)); |
199 expect(new Int64(5) ~/ new Int64(5), Int64.ONE); | 199 expect(new Int64(5) ~/ new Int64(5), Int64.ONE); |
200 expect(new Int64(1000) ~/ new Int64(3), new Int64(333)); | 200 expect(new Int64(1000) ~/ new Int64(3), new Int64(333)); |
201 expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333)); | 201 expect(new Int64(1000) ~/ new Int64(-3), new Int64(-333)); |
202 expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); | 202 expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333)); |
203 expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); | 203 expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333)); |
204 expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); | 204 expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO); |
205 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ | 205 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ |
206 new Int64.fromInts(0x0, 0x123), | 206 new Int64.fromInts(0x0, 0x123), |
207 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); | 207 new Int64.fromInts(0x1003d0, 0xe84f5ae8)); |
208 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ | 208 expect(new Int64.fromInts(0x12345678, 0x12345678) ~/ |
209 new Int64.fromInts(0x1234, 0x12345678), | 209 new Int64.fromInts(0x1234, 0x12345678), |
210 new Int64.fromInts(0x0, 0x10003)); | 210 new Int64.fromInts(0x0, 0x10003)); |
211 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 211 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
212 new Int64.fromInts(0x1234, 0x12345678), | 212 new Int64.fromInts(0x1234, 0x12345678), |
213 new Int64.fromInts(0xffffffff, 0xffff3dfe)); | 213 new Int64.fromInts(0xffffffff, 0xffff3dfe)); |
214 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ | 214 expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/ |
215 new Int64.fromInts(0xffff1234, 0x12345678), | 215 new Int64.fromInts(0xffff1234, 0x12345678), |
216 new Int64.fromInts(0x0, 0xeda)); | 216 new Int64.fromInts(0x0, 0xeda)); |
217 expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); | 217 expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461)); |
218 expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); | 218 expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461)); |
219 expect(new Int64(829893893) ~/ 1919, new Int32(432461)); | 219 expect(new Int64(829893893) ~/ 1919, new Int32(432461)); |
220 expect(() => new Int64(1) ~/ Int64.ZERO, | 220 expect(() => new Int64(1) ~/ Int64.ZERO, |
221 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); | 221 throwsA(new isInstanceOf<IntegerDivisionByZeroException>())); |
222 expect(Int64.MIN_VALUE ~/ new Int64(2), | 222 expect(Int64.MIN_VALUE ~/ new Int64(2), |
223 new Int64.fromInts(0xc0000000, 0x00000000)); | 223 new Int64.fromInts(0xc0000000, 0x00000000)); |
224 expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); | 224 expect(Int64.MIN_VALUE ~/ new Int64(1), Int64.MIN_VALUE); |
225 expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); | 225 expect(Int64.MIN_VALUE ~/ new Int64(-1), Int64.MIN_VALUE); |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); | 866 expect(Int64.MAX_VALUE.toRadixString(13), "10b269549075433c37"); |
867 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); | 867 expect(Int64.MAX_VALUE.toRadixString(14), "4340724c6c71dc7a7"); |
868 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); | 868 expect(Int64.MAX_VALUE.toRadixString(15), "160e2ad3246366807"); |
869 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); | 869 expect(Int64.MAX_VALUE.toRadixString(16), "7fffffffffffffff"); |
870 expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); | 870 expect(() => new Int64(42).toRadixString(-1), throwsArgumentError); |
871 expect(() => new Int64(42).toRadixString(0), throwsArgumentError); | 871 expect(() => new Int64(42).toRadixString(0), throwsArgumentError); |
872 expect(() => new Int64(42).toRadixString(37), throwsArgumentError); | 872 expect(() => new Int64(42).toRadixString(37), throwsArgumentError); |
873 }); | 873 }); |
874 }); | 874 }); |
875 } | 875 } |
OLD | NEW |