OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart test for testing bitwise operations. | 4 // Dart test for testing bitwise operations. |
| 5 // This test includes bitwise operations on very large numbers to test |
| 6 // the arbitrary precision integer support in dart. |
5 | 7 |
6 class BitOperationsTest { | 8 class BitOperationsVMTest { |
7 static testMain() { | 9 static testMain() { |
8 for (int i = 0; i < 4; i++) { | 10 for (int i = 0; i < 4; i++) { |
9 testOne(); | 11 testOne(); |
10 } | 12 } |
11 } | 13 } |
12 static testOne() { | 14 static testOne() { |
13 Expect.equals(3, (3 & 7)); | |
14 Expect.equals(7, (3 | 7)); | |
15 Expect.equals(4, (3 ^ 7)); | |
16 Expect.equals(25, (100 >> 2)); | |
17 Expect.equals(400, (100 << 2)); | |
18 Expect.equals(-25, (-100 >> 2)); | |
19 Expect.equals(-101, ~100); | |
20 Expect.equals(0x10000000000000000, 1 << 64); | 15 Expect.equals(0x10000000000000000, 1 << 64); |
21 Expect.equals(-0x10000000000000000, -1 << 64); | 16 Expect.equals(-0x10000000000000000, -1 << 64); |
22 Expect.equals(0x40000000, 0x04000000 << 4); | 17 Expect.equals(0x40000000, 0x04000000 << 4); |
23 Expect.equals(0x4000000000000000, 0x0400000000000000 << 4); | 18 Expect.equals(0x4000000000000000, 0x0400000000000000 << 4); |
24 Expect.equals(0, ~-1); | |
25 Expect.equals(-1, ~0); | |
26 | 19 |
27 Expect.equals(0, 1 >> 160); | 20 Expect.equals(0, 1 >> 160); |
28 Expect.equals(-1, -1 >> 160); | 21 Expect.equals(-1, -1 >> 160); |
29 | 22 |
30 Expect.equals(0x100000000000000001, | 23 Expect.equals(0x100000000000000001, |
31 0x100000000000000001 & 0x100000100F00000001); | 24 0x100000000000000001 & 0x100000100F00000001); |
32 Expect.equals(0x1, 0x1 & 0x100000100F00000001); | 25 Expect.equals(0x1, 0x1 & 0x100000100F00000001); |
33 Expect.equals(0x1, 0x100000100F00000001 & 0x1); | 26 Expect.equals(0x1, 0x100000100F00000001 & 0x1); |
34 | 27 |
35 Expect.equals(0x100000100F00000001, | 28 Expect.equals(0x100000100F00000001, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 Expect.equals(-1, ShiftRight(-1, shift)); | 81 Expect.equals(-1, ShiftRight(-1, shift)); |
89 Expect.equals(true, ShiftLeft(1, shift) > ShiftLeft(1, shift - 1)); | 82 Expect.equals(true, ShiftLeft(1, shift) > ShiftLeft(1, shift - 1)); |
90 } | 83 } |
91 } | 84 } |
92 | 85 |
93 static int ShiftLeft(int a, int b) { return a << b; } | 86 static int ShiftLeft(int a, int b) { return a << b; } |
94 static int ShiftRight(int a, int b) { return a >> b; } | 87 static int ShiftRight(int a, int b) { return a >> b; } |
95 } | 88 } |
96 | 89 |
97 main() { | 90 main() { |
98 BitOperationsTest.testMain(); | 91 BitOperationsVMTest.testMain(); |
99 } | 92 } |
OLD | NEW |