// Pyret's `is`, for Java.
//
// Given: keep this file beside yours and do not edit it. In main, write
//
//     Check.is(stripeWidth(10), 60);
//
// once per example, and Check.done() as the last line. A check that fails
// prints what it got and what it expected; done() prints the count.
//
// You are welcome to read it. Everything in here is Java you have seen or
// will see within a few weeks, and where it is the latter, a comment says so.

// A class is a box that methods live in. `Check` is the name you type before
// the dot; what a class is for, properly, is week 6.
class Check {
    // Two counts that go up as the checks run. `static` means there is one
    // of each for the whole program, not one per anything. Week 6 as well.
    static int passed = 0;
    static int failed = 0;

    // Four `is`, all with the same name, one per kind of value. Java picks
    // the one whose types match what you pass: the first for stripeWidth(10)
    // and 60, the last for flagRow(1) and text. `static` on a method is what
    // lets you write Check.is(...) without making a Check first.
    //
    // Two numbers are equal when == says so. Two strings are equal when
    // .equals says so, and why those are two different questions is next
    // class.
    static void is(int got, int expected)         { record(got == expected, "" + got, "" + expected); }
    static void is(double got, double expected)   { record(got == expected, "" + got, "" + expected); }
    static void is(boolean got, boolean expected) { record(got == expected, "" + got, "" + expected); }
    static void is(String got, String expected)   { record(got.equals(expected), got, expected); }

    // Every `is` ends up here with the verdict and both values as text, so a
    // failure prints the same way whatever the type was. `"" + got` is how a
    // number becomes text: + joins, and joins a number onto text without
    // being asked.
    static void record(boolean ok, String got, String expected) {
        if (ok) {
            passed = passed + 1;
        } else {
            failed = failed + 1;
            IO.println("FAIL check " + (passed + failed) + ": got " + got + ", expected " + expected);
        }
    }

    // The last line of main: Pyret's "Looks shipshape", or the two counts.
    static void done() {
        if (failed == 0) {
            IO.println("Looks shipshape, all " + passed + " checks passed");
        } else {
            IO.println(passed + " passed, " + failed + " FAILED");
        }
    }
}
