/*  AutoTester.java
 *  Geoff Oakham (oakhamg@cs)
 *  Nov 5, 2001
 */

import java.util.*;
import java.io.*;
import java.lang.*;

/** An autotester for csc148.s02.A4. */
class TestCases {

    //The total number of tests
    static public int TOTAL_TESTS = 37;
    static public int FREE_MARKS = 0;


    /** Performs test number "testNumber" and returns the outcome of the test.
     * All exceptions are thrown back to the caller.  (Yes, this is bad style,
     * but it saves having to copy & paste exception handling code.)
     * Preconditions: 0 <= testNumber < TOTAL_TESTS,
     *   and runTest(i) for i < testNumber has previously been called (once
     *   each.)
     */
    public boolean runTest(int testNumber) throws Exception {
        boolean r;
        
        A0 a;
        String s;

        r = true;

        //Set test parameters
        switch (testNumber) {
            // Single even element - expecting true
        case 0:
	    a = new A0();
	    int[] array0 = {2};
	    r = a.isEvenAscending(array0);
            break;

	    // Single even element not starting at 2 - expecting true
        case 1:
            a = new A0();
	    int []array1 = {8};
	    r = a.isEvenAscending(array1);
            break;

	    // Multiple elements, no gaps - expecting true
        case 2:
            a = new A0();
	    int[] array2 = {2, 4, 6, 8};
	    r = a.isEvenAscending(array2);
            break;

	    // Multiple elements, with gaps - expecting true
        case 3:
            a = new A0();
	    int[] array3 = {2, 6, 12, 24};
	    r = a.isEvenAscending(array3);
            break;

	    // Empty list - expecting false
        case 4:
            a = new A0();
	    int[] array4 = {};
	    r = !a.isEvenAscending(array4);
            break;

	    // Multiple elements, all negative - expecting true
        case 5:
            a = new A0();
	    int[] array5 = {-8, -4, -2};
	    r = a.isEvenAscending(array5);
            break;

	    // Multiple elements, crossing zero - expecting true
        case 6:
            a = new A0();
	    int[] array6 = {-8, -2, 0, 2};
	    r = a.isEvenAscending(array6);
            break;

	    // An element is duplicated - expecting false
        case 7:
            a = new A0();
	    int[] array7 = {2, 2, 4, 6};
	    r = !a.isEvenAscending(array7);
            break;

	    // An odd number in the middle of the list - expecting false
        case 8:
            a = new A0();
	    int[] array8 = {2, 3, 4};
	    r = !a.isEvenAscending(array8);
            break;

	    // An odd number at the end of the list - expecting false
        case 9:
            a = new A0();
	    int[] array9 = {2, 4, 5};
	    r = !a.isEvenAscending(array9);
            break;

	    // A list of non-ascending even numbers - expecting false
        case 10:
            a = new A0();
	    int[] array10 = {2, 4, 6, 4, 8};
	    r = !a.isEvenAscending(array10);
            break;

	    // Test isSquareSequence
	    // Single element - expecting true
        case 11:
            a = new A0();
	    int[] array11 = {4};
	    r = a.isSquareSequence(array11);
            break;

	    // Multiple elements - expecting true
        case 12:
            a = new A0();
	    int[] array12 = {1, 4, 9, 16};
	    r = a.isSquareSequence(array12);
            break;

	    // Multiple elements not starting at 1 - expecting true
        case 13:
            a = new A0();
	    int[] array13 = {16, 25, 36};
	    r = a.isSquareSequence(array13);
            break;

	    // Last element not a square - expecting false
        case 14:
            a = new A0();
	    int[] array14 = {1, 4, 8};
	    r = !a.isSquareSequence(array14);
            break;

	    // First element not a square - expecting false
        case 15:
            a = new A0();
	    int[] array15 = {3, 4, 8};
	    r = !a.isSquareSequence(array15);
            break;

	    // Gap in sequence - expecting false
        case 16:
            a = new A0();
	    int[] array16 = {4, 16, 25};
	    r = !a.isSquareSequence(array16);
            break;

	    // Negative number in sequence - expecting false
        case 17:
            a = new A0();
	    int[] array17 = {-1, 4, 9};
	    r = !a.isSquareSequence(array17);
            break;

	    // 0 and 1 are both squares - expecting true
        case 18:
            a = new A0();
	    int[] array18 = {0, 1};
	    r = a.isSquareSequence(array18);
            break;

	    // Empty list - expecting false
        case 19:
            a = new A0();
	    int[] array19 = {};
	    r = !a.isSquareSequence(array19);
            break;

	    // test isPalindrome
	    // Odd number of characters, only letters - expecting true
        case 20:
            a = new A0();
	    s = "aba";
	    r = a.isPalindrome(s);
            break;

	    // Even number of characters, only letters - expecting true
        case 21:
            a = new A0();
	    s = "abba";
	    r = a.isPalindrome(s);
            break;

	    // Single letter - expecting true
        case 22:
            a = new A0();
	    s = "a";
	    r = a.isPalindrome(s);
            break;

	    // Single capital letter - expecting true
        case 23:
            a = new A0();
	    s = "I";
	    r = a.isPalindrome(s);
            break;

	    // String with internal punctuation - expecting true
        case 24:
            a = new A0();
	    s = "ab.a";
	    r = a.isPalindrome(s);
            break;

	    //  Longer string (multiple loop iterations) - expecting true
        case 25:
            a = new A0();
	    s = "cabac";
	    r = a.isPalindrome(s);
            break;

	    // String with capital letters - expecting true.
        case 26:
            a = new A0();
	    s = "Cabac";
	    r = a.isPalindrome(s);
            break;

	    // String with puctuation at the end - expecting true
        case 27:
            a = new A0();
	    s = "cabac#";
	    r = a.isPalindrome(s);
            break;

	    // String with spaces - expecting true
        case 28:
            a = new A0();
	    s = "c ab ac";
	    r = a.isPalindrome(s);
            break;

	    // Short non-palindrome - expecting false
        case 29:
            a = new A0();
	    s = "abc";
	    r = !a.isPalindrome(s);
            break;

	    // Even number of letters, not a palindrome - expecting false
        case 30:
            a = new A0();
	    s = "dabc";
	    r = !a.isPalindrome(s);
            break;

	    // Internal palindrome but whole string not a palindrome -
	    // expecting false
        case 31:
            a = new A0();
	    s = "d aba c";
	    r = !a.isPalindrome(s);
            break;

	    // Punctuation in a non-palindrome - expecting false
        case 32:
            a = new A0();
	    s = "Dab!a% c";
	    r = !a.isPalindrome(s);
            break;

	    // Some strings from the palindrome list - these tests
	    // are redundant except that they check different punctuation
	    // characters in different positions in the string
	    // The remaining tests should return true.
        case 33:
            a = new A0();
	    s = "A Toyota";
	    r = a.isPalindrome(s);
            break;

        case 34:
            a = new A0();
	    s = "Never odd or even.";
	    r = a.isPalindrome(s);
            break;

            //Random test cases
        case 35:
            a = new A0();
	    s = "Go hang a salami, I'm a lasagna hog.";
	    r = a.isPalindrome(s);
            break;

        case 36:
            a = new A0();
	    s = "\"Madam, I'm Adam.\" ";
	    r = a.isPalindrome(s);
            break;

        default:
            throw new Error();
        }
    
        return r;
    }
}

