/**
 * CS-20  Asg6
 * MyGradeTest.java
 * Purpose: Tests the MyGradebook class
 *
 * @author Ed Parrish
 * @version 1.0 10/04/03
 */
public class MyGradeTest {
    /**
     * The main program for the ComplexTest class
     *
     * @param args -- not used
     */
    public static void main(String args[]) {
        testMyGradebook();
        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);
        }
    }

    /**
     * Test method: public MyGradebook() and get methods
     */
    public static void testMyGradebook() {
        System.out.println("Testing MyGradebook()");
        MyGradebook g = new MyGradebook();
        MyScores[] scores = g.getScores();
        assertTrue(scores.length == MyGradebook.SCORE_TYPES,
            "Wrong number of scores: " + scores.length);
        for (int i = 0; i < scores.length; i++) {
            assertTrue(scores[i] != null,
                "No scores data for element " + i);
            if (scores[i] instanceof MyAsn) {
                assertTrue(scores[i].getName() != null,
                    "No name for MyAsn");
            } else if (scores[i] instanceof MyTest) {
                assertTrue(scores[i].getName() != null,
                    "No name for MyTest");
            } else {
                Class c = scores[i].getClass();
                assertTrue(false, "Unknown subclass:" + c.getName());
            }
        }
    }
}

