| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 int zero() { return 0; } | |
| 6 int one() { return 1; } | |
| 7 int minus1() { return 0 - 1; } | |
| 8 int two() { return 2; } | |
| 9 int three() { return 3; } | |
| 10 int five() { return 5; } | |
| 11 int minus5() { return 0 - 5; } | |
| 12 int ninetyNine() { return 99; } | |
| 13 int four99() { return 499; } | |
| 14 int four99times99() { return 499 * 99; } | |
| 15 int four99times99plus1() { return 499 * 99 + 1; } | |
| 16 | |
| 17 void addTest() { | |
| 18 var m1 = 0 - 1; | |
| 19 var x = 0; | |
| 20 x += 0; | |
| 21 Expect.equals(0, x); | |
| 22 x += one(); | |
| 23 Expect.equals(1, x); | |
| 24 x += m1; | |
| 25 Expect.equals(0, x); | |
| 26 x += 499; | |
| 27 Expect.equals(499, x); | |
| 28 } | |
| 29 | |
| 30 void subTest() { | |
| 31 var m1 = 0 - 1; | |
| 32 var x = 0; | |
| 33 x -= 0; | |
| 34 Expect.equals(0, x); | |
| 35 x -= one(); | |
| 36 Expect.equals(m1, x); | |
| 37 x -= m1; | |
| 38 Expect.equals(0, x); | |
| 39 x = 499; | |
| 40 x -= one(); | |
| 41 x -= 98; | |
| 42 Expect.equals(400, x); | |
| 43 } | |
| 44 | |
| 45 void mulTest() { | |
| 46 var m1 = 0 - 1; | |
| 47 var x = 0; | |
| 48 x *= 0; | |
| 49 Expect.equals(0, x); | |
| 50 x = one(); | |
| 51 x *= 1; | |
| 52 Expect.equals(1, x); | |
| 53 x *= four99(); | |
| 54 Expect.equals(499, x); | |
| 55 x *= m1; | |
| 56 Expect.equals(0 - 499, x); | |
| 57 } | |
| 58 | |
| 59 void divTest() { | |
| 60 var m1 = 0.0 - 1.0; | |
| 61 var m2 = 0 - 2; | |
| 62 var x = two(); | |
| 63 x /= 2; | |
| 64 Expect.equals(1.0, x); | |
| 65 x /= 2; | |
| 66 Expect.equals(0.5, x); | |
| 67 x = four99times99(); | |
| 68 x /= 99; | |
| 69 Expect.equals(499.0, x); | |
| 70 } | |
| 71 | |
| 72 void tdivTest() { | |
| 73 var x = 3; | |
| 74 x ~/= two(); | |
| 75 Expect.equals(1, x); | |
| 76 x = 49402; | |
| 77 x ~/= ninetyNine(); | |
| 78 Expect.equals(499, x); | |
| 79 } | |
| 80 | |
| 81 void modTest() { | |
| 82 var x = five(); | |
| 83 x %= 3; | |
| 84 Expect.equals(2, x); | |
| 85 x = 49402; | |
| 86 x %= ninetyNine(); | |
| 87 Expect.equals(1, x); | |
| 88 } | |
| 89 | |
| 90 void shlTest() { | |
| 91 var x = five(); | |
| 92 x <<= 2; | |
| 93 Expect.equals(20, x); | |
| 94 x <<= 1; | |
| 95 Expect.equals(40, x); | |
| 96 } | |
| 97 | |
| 98 void shrTest() { | |
| 99 var x = four99(); | |
| 100 x >>= 1; | |
| 101 Expect.equals(249, x); | |
| 102 x >>= 2; | |
| 103 Expect.equals(62, x); | |
| 104 } | |
| 105 | |
| 106 void andTest() { | |
| 107 var x = five(); | |
| 108 x &= 3; | |
| 109 Expect.equals(1, x); | |
| 110 x &= 10; | |
| 111 Expect.equals(0, x); | |
| 112 x = four99(); | |
| 113 x &= 63; | |
| 114 Expect.equals(51, x); | |
| 115 } | |
| 116 | |
| 117 void orTest() { | |
| 118 var x = five(); | |
| 119 x |= 2; | |
| 120 Expect.equals(7, x); | |
| 121 x |= 7; | |
| 122 Expect.equals(7, x); | |
| 123 x |= 10; | |
| 124 Expect.equals(15, x); | |
| 125 x |= 499; | |
| 126 Expect.equals(511, x); | |
| 127 } | |
| 128 | |
| 129 void xorTest() { | |
| 130 var x = five(); | |
| 131 x ^= 2; | |
| 132 Expect.equals(7, x); | |
| 133 x ^= 7; | |
| 134 Expect.equals(0, x); | |
| 135 x ^= 10; | |
| 136 Expect.equals(10, x); | |
| 137 x ^= 499; | |
| 138 Expect.equals(505, x); | |
| 139 } | |
| 140 | |
| 141 void main() { | |
| 142 addTest(); | |
| 143 subTest(); | |
| 144 mulTest(); | |
| 145 divTest(); | |
| 146 tdivTest(); | |
| 147 modTest(); | |
| 148 shlTest(); | |
| 149 shrTest(); | |
| 150 andTest(); | |
| 151 orTest(); | |
| 152 xorTest(); | |
| 153 } | |
| OLD | NEW |