/*
 * AllTest.java
 *
 * Created on March 24, 2006, 3:42 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.example.model;
import junit.framework.*;
import java.util.*;
import java.io.*;
/**
 *
 * @author Steven R. Brennan
 */
public class AllTest extends TestCase {
    
    
    /* This test is for the following functions:
     * Schedule: 
     *  printFreeSchedule()
     *  setFreeSchedule()
     * 
     * Parser:
     * createFreeSchedule()
     *
     *
     * - printFreeSchedule is only a method to ensure 
     *   setFreeSchedule ran properly
     *           
     */
    public void testSimpleParser(){
        
        Parser testParser = new Parser();
        
    	String[] free_times = new String[5];
	free_times[0] = new String("0:1-2;1:1-3"); //monday
	free_times[1] = new String("0:1-2;1:1-3"); //tuesday
	free_times[2] = new String("0:1-2;1:1-3"); //wednesday
	free_times[3] = new String("0:1-2;1:1-3"); //thursday
	free_times[4] = new String("0:1-2;1:1-3"); //friday

       // Schedule testSched = new Schedule(2);
        
	Schedule testSched = testParser.createSchedule(free_times);

        testSched.setFreeSchedule();
        
        String actualFreeOutput = testSched.printFreeSchedule();
        System.out.println( actualFreeOutput );        
        String expectedResult = "Day: M, Hour: 1pm"  + '\n' +
                                "Day: M, Hour: 2pm"  + '\n' +
                                "Day: T, Hour: 1pm"  + '\n' +
                                "Day: T, Hour: 2pm"  + '\n' +
                                "Day: W, Hour: 1pm"  + '\n' +
                                "Day: W, Hour: 2pm"  + '\n' +
                                "Day: TR, Hour: 1pm" + '\n' +
                                "Day: TR, Hour: 2pm" + '\n' +
                                "Day: F, Hour: 1pm"  + '\n' +
                                "Day: F, Hour: 2pm"  + '\n';
        
        //test if Parser: createSchedule() worked correctly
        Assert.assertEquals(1, testSched.getFreeSchedule(6, 2) ); 
        
        //test if setFreeSchedule() worked correctly
        //note: this test uses output by printFreeSchedule();
        Assert.assertEquals(expectedResult, actualFreeOutput );
    
    }
    
    /* This is a test for Student:
     *  getFreeHour()
     *  setHourAsFree()
     *
     * Both methods are set and get methods that return 1, 0, or -1 if error
     */
    public void testSimpleStudent(){
        
        Student testStudent_1 = new Student();
        Student testStudent_2 = new Student();
        
        int returnVal = testStudent_1.setHourAsFree(2, 2);
        
        Assert.assertEquals(1, returnVal ); //test for setHourAsFree ran successfully
        Assert.assertEquals(1, testStudent_1.getFreeHour(2, 2) ); //returns 1
        Assert.assertEquals(0, testStudent_2.getFreeHour(1, 1) ); //Default = Free = 0

    }
        
    
    /* This test is for the Schedule:
     * Schedule:
     *  setSchedule()
     */
    public void testSimpleSchedule(){
        
        Schedule testSched = new Schedule(3);
        
        Assert.assertEquals(1, testSched.setSchedule(2, 3, 4 ) );
    } 
        
}
