Skip to content

Commit a912414

Browse files
committed
Update AboutConditionals.java
maybe it's convoluted, but this should close matyb#77
1 parent 35a0256 commit a912414

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

‎koans/src/beginner/AboutConditionals.java‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,36 @@ public void switchStatementSwitchValues() {
147147

148148
@Koan
149149
public void shortCircuit() {
150-
int i = 1;
151-
int a = 6;
152-
// Why did we use a variable here?
153-
// What happens if you replace 'a' with '6' below?
154-
if ((a < 9) || (++i < 8)) i = i + 1;
155-
assertEquals(i, __);
150+
counter trueCount = new Counter(true);
151+
counter falseCount = new Counter(false);
152+
String x = "Hai";
153+
if (trueCount.count() || falseCount.count()) {
154+
x = "kthxbai";
155+
}
156+
assertEquals(x, __);
157+
assertEquals(trueCount.count, __);
158+
assertEquals(falseCount.count, __);
159+
}
160+
161+
@Koan
162+
public void bitwise() {
163+
counter trueCount = new Counter(true);
164+
counter falseCount = new Counter(false);
165+
String x = "Hai";
166+
if (trueCount.count() | falseCount.count()) {
167+
x = "kthxbai";
168+
}
169+
assertEquals(x, __);
170+
assertEquals(trueCount.count, __);
171+
assertEquals(falseCount.count, __);
172+
}
173+
174+
class Counter {
175+
boolean returnValue;
176+
int count = 0;
177+
boolean count() {
178+
count++;
179+
return returnValue;
180+
}
156181
}
157182
}

0 commit comments

Comments
 (0)