package org.treesched.regression;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.treesched.Interval;
import org.treesched.Schedule;

/**
 * 
 */
public class TestScheduleRun {

	private Date testDate;
	private String stringDate;
	
	private Expected expected; 
	
	public void setDate(String date) throws ParseException {
		DateFormat format = new SimpleDateFormat("dd-MMM-yy HH:mm");
		this.stringDate = date;
		testDate = format.parse(stringDate);	    
	}
	
	public String getDate() {
	    return stringDate;
	}
	
	public void addExpected(Expected expected) {
	    this.expected = expected;
	}
		
	public boolean testSchedule(Schedule schedule) {

		DateFormat format = new SimpleDateFormat("dd-MMM-yy HH:mm:ss:SSS");
		Interval nextDue = schedule.nextDue(testDate);
		boolean result;
		if (expected == null) {
			result = true;
		}
		else {
			result = expected.getExpected().equals(nextDue); 
		}
		System.out.println("Given [" + format.format(testDate)
			+ "]: next due " + nextDue + ". " + (result ? "OK" : "WRONG - " + expected));
				
		return result;
	}
}
