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 | 5 |
6 class BitOperationsTest { | 6 class BitOperationsTest { |
7 static testMain() { | 7 static testMain() { |
8 for (int i = 0; i < 4; i++) { | 8 for (int i = 0; i < 4; i++) { |
9 testOne(); | 9 testOne(); |
10 } | 10 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 Expect.equals(15, 0xF00000000 >> 32); | 47 Expect.equals(15, 0xF00000000 >> 32); |
48 Expect.equals(1030792151040, 16492674416655 >> 4); | 48 Expect.equals(1030792151040, 16492674416655 >> 4); |
49 | 49 |
50 Expect.equals(0xF0000000000000000F0, 0xF0000000000000000F << 4); | 50 Expect.equals(0xF0000000000000000F0, 0xF0000000000000000F << 4); |
51 Expect.equals(0xF00000000, 15 << 32); | 51 Expect.equals(0xF00000000, 15 << 32); |
52 | 52 |
53 TestNegativeValueShifts(); | 53 TestNegativeValueShifts(); |
54 TestPositiveValueShifts(); | 54 TestPositiveValueShifts(); |
55 TestNoMaskingOfShiftCount(); | 55 TestNoMaskingOfShiftCount(); |
56 TestNegativeCountShifts(); | 56 TestNegativeCountShifts(); |
57 for (int i = 0; i < 1000; i++) { | 57 for (int i = 0; i < 10000; i++) { |
58 TestCornerCasesLeftShifts(); | 58 TestCornerCasesRightShifts(); |
| 59 TestRightShift64Bit(); |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 static void TestCornerCasesLeftShifts() { | 63 static void TestCornerCasesRightShifts() { |
63 var v32 = 0xFF000000; | 64 var v32 = 0xFF000000; |
64 var v64 = 0xFF00000000000000; | 65 var v64 = 0xFF00000000000000; |
65 Expect.equals(0x3, v32 >> 0x1E); | 66 Expect.equals(0x3, v32 >> 0x1E); |
66 Expect.equals(0x1, v32 >> 0x1F); | 67 Expect.equals(0x1, v32 >> 0x1F); |
67 Expect.equals(0x0, v32 >> 0x20); | 68 Expect.equals(0x0, v32 >> 0x20); |
68 Expect.equals(0x3, v64 >> 0x3E); | 69 Expect.equals(0x3, v64 >> 0x3E); |
69 Expect.equals(0x1, v64 >> 0x3F); | 70 Expect.equals(0x1, v64 >> 0x3F); |
70 Expect.equals(0x0, v64 >> 0x40); | 71 Expect.equals(0x0, v64 >> 0x40); |
71 } | 72 } |
72 | 73 |
| 74 static void TestRightShift64Bit() { |
| 75 var t = 0x1ffffffff; |
| 76 Expect.equals(0xffffffff, t >> 1); |
| 77 } |
| 78 |
73 static void TestNegativeCountShifts() { | 79 static void TestNegativeCountShifts() { |
74 bool throwOnLeft(a, b) { | 80 bool throwOnLeft(a, b) { |
75 try { | 81 try { |
76 var x = a << b; | 82 var x = a << b; |
77 return false; | 83 return false; |
78 } catch (e) { | 84 } catch (e) { |
79 return true; | 85 return true; |
80 } | 86 } |
81 } | 87 } |
82 | 88 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 138 } |
133 } | 139 } |
134 | 140 |
135 static int ShiftLeft(int a, int b) { return a << b; } | 141 static int ShiftLeft(int a, int b) { return a << b; } |
136 static int ShiftRight(int a, int b) { return a >> b; } | 142 static int ShiftRight(int a, int b) { return a >> b; } |
137 } | 143 } |
138 | 144 |
139 main() { | 145 main() { |
140 BitOperationsTest.testMain(); | 146 BitOperationsTest.testMain(); |
141 } | 147 } |
OLD | NEW |