From b303c0e672cf748501b70b572db75e83ee90439f Mon Sep 17 00:00:00 2001 From: Mat Bentley Date: Wed, 7 Feb 2018 00:54:45 -0500 Subject: [PATCH 1/3] Update AboutConditionals.java maybe it's convoluted, but this should close #77 --- koans/src/beginner/AboutConditionals.java | 37 +++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/koans/src/beginner/AboutConditionals.java b/koans/src/beginner/AboutConditionals.java index f7883dfb..81f6a7a5 100644 --- a/koans/src/beginner/AboutConditionals.java +++ b/koans/src/beginner/AboutConditionals.java @@ -147,11 +147,36 @@ public void switchStatementSwitchValues() { @Koan public void shortCircuit() { - int i = 1; - int a = 6; - // Why did we use a variable here? - // What happens if you replace 'a' with '6' below? - if ((a < 9) || (++i < 8)) i = i + 1; - assertEquals(i, __); + counter trueCount = new Counter(true); + counter falseCount = new Counter(false); + String x = "Hai"; + if (trueCount.count() || falseCount.count()) { + x = "kthxbai"; + } + assertEquals(x, __); + assertEquals(trueCount.count, __); + assertEquals(falseCount.count, __); + } + + @Koan + public void bitwise() { + counter trueCount = new Counter(true); + counter falseCount = new Counter(false); + String x = "Hai"; + if (trueCount.count() | falseCount.count()) { + x = "kthxbai"; + } + assertEquals(x, __); + assertEquals(trueCount.count, __); + assertEquals(falseCount.count, __); + } + + class Counter { + boolean returnValue; + int count = 0; + boolean count() { + count++; + return returnValue; + } } } From 5d4fc740a255bc688e6b82e266fcce9c1ad05b14 Mon Sep 17 00:00:00 2001 From: Mat Bentley Date: Wed, 7 Feb 2018 11:12:29 -0500 Subject: [PATCH 2/3] compile error, editing on github + phone @LifeIsALesson good catch --- koans/src/beginner/AboutConditionals.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/koans/src/beginner/AboutConditionals.java b/koans/src/beginner/AboutConditionals.java index 81f6a7a5..1fda562c 100644 --- a/koans/src/beginner/AboutConditionals.java +++ b/koans/src/beginner/AboutConditionals.java @@ -174,6 +174,9 @@ public void bitwise() { class Counter { boolean returnValue; int count = 0; + Counter(boolean returnValue) { + this.returnValue = returnValue; + } boolean count() { count++; return returnValue; From e8f064eea5aabe9277b02a412159edd9284743c5 Mon Sep 17 00:00:00 2001 From: Mat Bentley Date: Wed, 7 Feb 2018 11:24:50 -0500 Subject: [PATCH 3/3] Update AboutConditionals.java --- koans/src/beginner/AboutConditionals.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/koans/src/beginner/AboutConditionals.java b/koans/src/beginner/AboutConditionals.java index 1fda562c..f97a9bc9 100644 --- a/koans/src/beginner/AboutConditionals.java +++ b/koans/src/beginner/AboutConditionals.java @@ -147,8 +147,8 @@ public void switchStatementSwitchValues() { @Koan public void shortCircuit() { - counter trueCount = new Counter(true); - counter falseCount = new Counter(false); + Counter trueCount = new Counter(true); + Counter falseCount = new Counter(false); String x = "Hai"; if (trueCount.count() || falseCount.count()) { x = "kthxbai"; @@ -160,8 +160,8 @@ public void shortCircuit() { @Koan public void bitwise() { - counter trueCount = new Counter(true); - counter falseCount = new Counter(false); + Counter trueCount = new Counter(true); + Counter falseCount = new Counter(false); String x = "Hai"; if (trueCount.count() | falseCount.count()) { x = "kthxbai";