| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 < 1000; i++) { |
| 58 TestCornerCasesLeftShifts(); | 58 TestCornerCasesLeftShifts(); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 static void TestCornerCasesLeftShifts() { | 62 static void TestCornerCasesLeftShifts() { |
| 63 var v32 = 0xFF000000; | 63 var v32 = 0xFF000000; |
| 64 var v64 = 0xFF00000000000000; | 64 var v64 = 0xFF00000000000000; |
| 65 Expect.equals(0x3, v32 >> 0x1E); | 65 Expect.equals(0x3, v32 >> 0x1E); |
| 66 Expect.equals(0x1, v32 >> 0x1F); | 66 Expect.equals(0x1, v32 >> 0x1F); |
| 67 Expect.equals(0x0, v32 >> 0x20); | 67 Expect.equals(0x0, v32 >> 0x20); |
| 68 Expect.equals(0x3, v64 >> 0x3E); | 68 Expect.equals(0x3, v64 >> 0x3E); |
| 69 Expect.equals(0x1, v64 >> 0x3F); | 69 Expect.equals(0x1, v64 >> 0x3F); |
| 70 Expect.equals(0x0, v64 >> 0x40); | 70 Expect.equals(0x0, v64 >> 0x40); |
| 71 } | 71 } |
| 72 | 72 |
| 73 static void TestNegativeCountShifts() { | 73 static void TestNegativeCountShifts() { |
| 74 bool throwOnLeft(a, b) { | 74 bool throwOnLeft(a, b) { |
| 75 try { | 75 try { |
| 76 var x = a << b; | 76 var x = a << b; |
| 77 return false; | 77 return false; |
| 78 } catch(var e) { | 78 } catch (e) { |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool throwOnRight(a, b) { | 83 bool throwOnRight(a, b) { |
| 84 try { | 84 try { |
| 85 var x = a >> b; | 85 var x = a >> b; |
| 86 return false; | 86 return false; |
| 87 } catch(var e) { | 87 } catch (e) { |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 Expect.isTrue(throwOnLeft(12, -3)); | 92 Expect.isTrue(throwOnLeft(12, -3)); |
| 93 Expect.isTrue(throwOnRight(12, -3)); | 93 Expect.isTrue(throwOnRight(12, -3)); |
| 94 for (int i = 0; i < 4000; i++) { | 94 for (int i = 0; i < 4000; i++) { |
| 95 Expect.isFalse(throwOnLeft(12, 3)); | 95 Expect.isFalse(throwOnLeft(12, 3)); |
| 96 Expect.isFalse(throwOnRight(12, 3)); | 96 Expect.isFalse(throwOnRight(12, 3)); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 static void TestNegativeValueShifts() { | 100 static void TestNegativeValueShifts() { |
| 101 for (int value = 0; value > -100; value--) { | 101 for (int value = 0; value > -100; value--) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 static int ShiftLeft(int a, int b) { return a << b; } | 135 static int ShiftLeft(int a, int b) { return a << b; } |
| 136 static int ShiftRight(int a, int b) { return a >> b; } | 136 static int ShiftRight(int a, int b) { return a >> b; } |
| 137 } | 137 } |
| 138 | 138 |
| 139 main() { | 139 main() { |
| 140 BitOperationsTest.testMain(); | 140 BitOperationsTest.testMain(); |
| 141 } | 141 } |
| OLD | NEW |