package beginner;


import com.sandwich.koan.Koan;

import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.assertEquals;


public class AboutConditionals {

    @Koan
    public void basicIf() {
        int x = 1;
        if (true) {
            x++;
        }
        assertEquals(x, __);
    }

    @Koan
    public void basicIfElse() {
        int x = 1;
        boolean secretBoolean = false;
        if (secretBoolean) {
            x++;
        } else {
            x--;
        }
        assertEquals(x, __);
    }

    @Koan
    public void basicIfElseIfElse() {
        int x = 1;
        boolean secretBoolean = false;
        boolean otherBooleanCondition = true;
        if (secretBoolean) {
            x++;
        } else if (otherBooleanCondition) {
            x = 10;
        } else {
            x--;
        }
        assertEquals(x, __);
    }

    @Koan
    public void nestedIfsWithoutCurlysAreReallyMisleading() {
        // Why are these ugly you ask? Well, try for yourself
        int x = 1;
        boolean secretBoolean = false;
        boolean otherBooleanCondition = true;
        // Ifs without curly braces are ugly and not recommended but still valid:
        if (secretBoolean) {
            x++;
        }
        if (otherBooleanCondition) {
            x = 10;
        } else {
            x--;
        }
        // Where does this else belong to!?
        assertEquals(x, __);
    }

    @Koan
    public void basicSwitchStatement() {
        int i = 1;
        String result = "Basic ";
        switch (i) {
            case 1:
                result += "One";
                break;
            case 2:
                result += "Two";
                break;
            default:
                result += "Nothing";
        }
        assertEquals(result, __);
    }

    @Koan
    public void switchStatementFallThrough() {
        int i = 1;
        String result = "Basic ";
        switch (i) {
            case 1:
                result += "One";
            case 2:
                result += "Two";
            default:
                result += "Nothing";
        }
        assertEquals(result, __);
    }

    @Koan
    public void switchStatementCrazyFallThrough() {
        int i = 5;
        String result = "Basic ";
        switch (i) {
            case 1:
                result += "One";
            default:
                result += "Nothing";
            case 2:
                result += "Two";
        }
        assertEquals(result, __);
    }

    @Koan
    public void switchStatementConstants() {
        int i = 5;
        // What happens if you remove the 'final' modifier?
        // What does this mean for case values?
        final int caseOne = 1;
        String result = "Basic ";
        switch (i) {
            case caseOne:
                result += "One";
                break;
            default:
                result += "Nothing";
        }
        assertEquals(result, __);
    }

    @Koan
    public void switchStatementSwitchValues() {
        // Try different (primitive) types for 'c'
        // Which types do compile?
        // Does boxing work?
        char c = 'a';
        String result = "Basic ";
        switch (c) {
            case 'a':
                result += "One";
                break;
            default:
                result += "Nothing";
        }
        assertEquals(result, __);
    }

    @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, __);
    }
}

@@ -3492,213 +3492,879 @@
     
-int i = 1;%0A        int a = 6;%0A        // Why did we use a variable here?
+counter trueCount = new Counter(true);%0A        counter falseCount = new Counter(false);%0A        String x = %22Hai%22;%0A        if (trueCount.count() %7C%7C falseCount.count()) %7B%0A            x = %22kthxbai%22;%0A        %7D%0A        assertEquals(x, __);%0A        assertEquals(trueCount.count, __);%0A        assertEquals(falseCount.count, __);
 %0A    
+%7D%0A
     
-// What happens if you replace 'a' with '6' below?%0A        if ((a %3C 9) %7C%7C (++i %3C 8)) i = i + 1;%0A        assertEquals(i, __);
+%0A    @Koan%0A    public void bitwise() %7B%0A        counter trueCount = new Counter(true);%0A        counter falseCount = new Counter(false);%0A        String x = %22Hai%22;%0A        if (trueCount.count() %7C falseCount.count()) %7B%0A            x = %22kthxbai%22;%0A        %7D%0A        assertEquals(x, __);%0A        assertEquals(trueCount.count, __);%0A        assertEquals(falseCount.count, __);%0A    %7D%0A    %0A    class Counter %7B%0A        boolean returnValue;%0A        int count = 0;%0A        boolean count() %7B%0A            count++;%0A            return returnValue;%0A        %7D
 %0A   

Update AboutConditionals.java