/**
 * CS-20  Asn 7
 * ArtOMaticTest.java
 * Purpose: Unit test of the ArtOMatic class and the MyShape classes.
 *
 * @version 1.0 3/19/05
 * @author Ed Parrish
 */
public class ArtOMaticTest {
    private static int numErrors;

    /**
     * The main method begins execution of the tests.
     *
     * @param args not used
     */
    public static void main(String args[]) {
        testArtOMatic();
        if (numErrors == 0) {
            System.out.println("*** All tests passed ***");
        }
    }

    /**
     * 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: public ArtOMatic() and get methods
     */
    public static void testArtOMatic() {
        System.out.println("Testing ArtOMatic()");
        int myLineCount = 0;
        int myOvalCount = 0;
        int myRectCount = 0;
        ArtOMatic am = new ArtOMatic();
        MyShape[] shapes = am.getShapes();
        assertTrue(shapes.length >= 15,
            "Not enough shapes specified: " + shapes.length);
        for (int i = 0; i < shapes.length; i++) {
            assertTrue(shapes[i] != null,
                "No shapes reference for element " + i);
            assertTrue(shapes[i] instanceof MyShape,
                "Shape is not an instanceof MyShape " + shapes[i]);
            Class c = shapes[i].getClass();
            String className = c.getName();
            assertTrue(!className.equalsIgnoreCase("MyShape"),
                "MyShape not declared abstract (it was instantiated)");
            assertTrue(shapes[i].toString() != null,
                "Method toString() does not return info for " + className);
            shapes[i].setX1(7);
            assertTrue(shapes[i].getX1() == 7,
                "Set/get X1 methods do not work for " + className);
            shapes[i].setY1(7);
            assertTrue(shapes[i].getY1() == 7,
                "Set/get Y1 methods do not work for " + className);
            shapes[i].setX2(7);
            assertTrue(shapes[i].getX2() == 7,
                "Set/get X2 methods do not work for " + className);
            shapes[i].setY2(7);
            assertTrue(shapes[i].getY2() == 7,
                "Set/get Y2 methods do not work for " + className);
            if (shapes[i] instanceof MyLine) myLineCount++;
            if (shapes[i] instanceof MyOval) myOvalCount++;
            if (shapes[i] instanceof MyRect) myRectCount++;
        }
        assertTrue(myLineCount > 0, "No MyLine shapes created");
        assertTrue(myOvalCount > 0, "No MyOval shapes created");
        assertTrue(myRectCount > 0, "No MyRect shapes created");
    }
}

