Chromium Code Reviews| 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 | 4 |
| 5 // Dart test program for testing basic boolean properties. | 5 // Dart test program for testing basic boolean properties. |
| 6 // @static-clean | 6 // @static-clean |
| 7 | 7 |
| 8 class BoolTest { | 8 class BoolTest { |
| 9 static void testEquality() { | 9 static void testEquality() { |
| 10 Expect.equals(true, true); | 10 Expect.equals(true, true); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 Expect.equals("false", false.toString()); | 105 Expect.equals("false", false.toString()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static void testNegate(isTrue, isFalse) { | 108 static void testNegate(isTrue, isFalse) { |
| 109 Expect.equals(true, !false); | 109 Expect.equals(true, !false); |
| 110 Expect.equals(false, !true); | 110 Expect.equals(false, !true); |
| 111 Expect.equals(true, !isFalse); | 111 Expect.equals(true, !isFalse); |
| 112 Expect.equals(false, !isTrue); | 112 Expect.equals(false, !isTrue); |
| 113 } | 113 } |
| 114 | 114 |
| 115 static void testLogicalOp() { | |
| 116 testOr(a, b, onTypeError) { | |
| 117 try { | |
| 118 return a || b; | |
| 119 } catch (TypeError t) { | |
| 120 return onTypeError; | |
| 121 } | |
| 122 } | |
| 123 testAnd(a, b, onTypeError) { | |
| 124 try { | |
| 125 return a && b; | |
| 126 } catch (TypeError t) { | |
| 127 return onTypeError; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 var isTrue = true; | |
| 132 var isFalse = false; | |
| 133 Expect.equals(true, testAnd(isTrue, isTrue, false)); | |
| 134 Expect.equals(false, testAnd(isTrue, 0, false)); | |
| 135 Expect.equals(false, testAnd(isTrue, 1, false)); | |
| 136 Expect.equals(false, testAnd(isTrue, "true", false)); | |
| 137 Expect.equals(false, testAnd(0, isTrue, false)); | |
| 138 Expect.equals(false, testAnd(1, isTrue, false)); | |
| 139 | |
| 140 Expect.equals(true, testOr(isTrue, isTrue, false)); | |
| 141 Expect.equals(true, testOr(isFalse, isTrue, false)); | |
| 142 Expect.equals(true, testOr(isTrue, isFalse, false)); | |
| 143 Expect.equals(true, testOr(isTrue, 0, true)); | |
| 144 Expect.equals(true, testOr(isTrue, 1, true)); | |
| 145 Expect.equals(false, testOr(isFalse, 0, false)); | |
| 146 Expect.equals(false, testOr(isFalse, 1, false)); | |
| 147 Expect.equals(true, testOr(0, isTrue, true)); | |
| 148 Expect.equals(true, testOr(1, isTrue, true)); | |
| 149 Expect.equals(false, testOr(0, isFalse, false)); | |
| 150 Expect.equals(false, testOr(1, isFalse, false)); | |
| 151 | |
| 152 // Test side effects. | |
| 153 int trueCount = 0; | |
| 154 int falseCount = 0; | |
| 155 | |
| 156 trueFunc() { | |
| 157 trueCount++; | |
| 158 return true; | |
| 159 } | |
| 160 | |
| 161 falseFunc() { | |
| 162 falseCount++; | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 Expect.equals(0, trueCount); | |
| 167 Expect.equals(0, falseCount); | |
| 168 | |
| 169 trueFunc() && trueFunc(); | |
| 170 Expect.equals(2, trueCount); | |
| 171 Expect.equals(0, falseCount); | |
| 172 | |
|
regis
2012/03/09 20:48:27
It would be easier to read if the counts were rese
srdjan
2012/03/09 21:14:55
Done.
| |
| 173 falseFunc() && trueFunc(); | |
| 174 Expect.equals(2, trueCount); | |
| 175 Expect.equals(1, falseCount); | |
| 176 | |
| 177 trueFunc() && falseFunc(); | |
| 178 Expect.equals(3, trueCount); | |
| 179 Expect.equals(2, falseCount); | |
| 180 | |
| 181 falseFunc() && falseFunc(); | |
| 182 Expect.equals(3, trueCount); | |
| 183 Expect.equals(3, falseCount); | |
| 184 | |
| 185 trueFunc() || trueFunc(); | |
| 186 Expect.equals(4, trueCount); | |
| 187 Expect.equals(3, falseCount); | |
| 188 | |
| 189 falseFunc() || trueFunc(); | |
| 190 Expect.equals(5, trueCount); | |
| 191 Expect.equals(4, falseCount); | |
| 192 | |
| 193 trueFunc() || falseFunc(); | |
| 194 Expect.equals(6, trueCount); | |
| 195 Expect.equals(4, falseCount); | |
| 196 | |
| 197 falseFunc() || falseFunc(); | |
| 198 Expect.equals(6, trueCount); | |
| 199 Expect.equals(6, falseCount); | |
| 200 } | |
| 201 | |
| 202 | |
| 115 static void testMain() { | 203 static void testMain() { |
| 116 testEquality(); | 204 testEquality(); |
| 117 testNegate(true, false); | 205 testNegate(true, false); |
| 118 testToString(); | 206 testToString(); |
| 207 testLogicalOp(); | |
| 119 } | 208 } |
| 120 } | 209 } |
| 121 | 210 |
| 122 main() { | 211 main() { |
| 123 BoolTest.testMain(); | 212 BoolTest.testMain(); |
| 124 } | 213 } |
| OLD | NEW |