/**
 * CS-12J Asn 7
 * BoardTest.java
 * Purpose: Unit test of the Board class.
 *
 * @version 1.0 10/29/05
 * @author Ed Parrish
 */
public final class BoardTest {
    private static int numErrors;

    /**
     * The main method begins execution of the tests.
     *
     * @param args not used
     */
    public static void main(final String[] args) {
        testBoard();
        testDisplayBoard();
        testIsOpenMove();
        testSetMove();
        testIsWinner();
        if (numErrors == 0) {
            System.out.println("*** All tests passed ***");
        }
        System.exit(0);
    }

    /**
     * Convenience method to test for assertions.
     *
     * @param condition The test condition that must be true to pass.
     * @param message The reason for the failure.
     */
    public static void assertTrue(boolean condition, String message) {
        if (!condition) {
            //throw new RuntimeException(message);
            System.out.println("Error: " + message);
            numErrors++;
        }
    }

    /**
     * Test method: Board()
     */
    public static void testBoard() {
        System.out.println("Testing Board()");
        Board b = new Board();
    }

    /**
     * Test method: displayBoard()
     */
    public static void testDisplayBoard() {
        System.out.println("Testing displayBoard()");
        Board b = new Board();
        System.out.println("  Here is the output of displayBoard()");
        b.displayBoard();
    }

    /**
     * Test method: isOpenMove()
     */
    public static void testIsOpenMove() {
        System.out.println("Testing isOpenMove()");
        Board b = new Board();
        for (int i = 0; i < 9; i++) {
            assertTrue(b.isOpenMove(i + 1),
                "isOpenMove() returns false before any plays are made");
        }
    }

    /**
     * Test method: setMove()
     */
    public static void testSetMove() {
        System.out.println("Testing setMove()");
        Board b = new Board();
        for (int i = 0; i < 9; i++) {
            assertTrue(b.isOpenMove(i + 1),
                "isOpenMove() returns false before any plays are made");
            b.setMove(i + 1, 'X');
            assertTrue(!b.isOpenMove(i + 1),
                "isOpenMove() returns true after setMove() is called");
        }
    }

    /**
     * Test method: isWinner()
     */
    public static void testIsWinner() {
        System.out.println("Testing isWinner()");
        Board b = new Board();
        assertTrue(!b.isWinner(),
            "isWinner() returns true before any plays are made");
        b.setMove(1, 'X');
        b.setMove(2, 'O');
        b.setMove(3, 'X');
        b.setMove(4, 'O');
        b.setMove(5, 'X');
        b.setMove(6, 'O');
        b.setMove(8, 'X');
        b.setMove(9, 'O');
        assertTrue(!b.isWinner(),
            "isWinner() returns true before any there is a winner");
        b.setMove(7, 'X');
        assertTrue(b.isWinner(),
            "isWinner() returns false when there is a winner");
    }
}

