///////////////////////////////////////////////////////////////////////////////
// Maximum Subsequence Problem
///////////////////////////////////////////////////////////////////////////////
//
// Test driver
//
// This test driver can be started with the command
// 		java MaxSequence <classname>
// where <classname> is the class which contains the solution, i.e. which
// implements the IMaxSequence interface.
//
// A dummy implementation is provided. It allows to test the test driver:
//		java MaxSequence SimpleSolution
//
// Compile this class with the command
//	javac -classpath .;u1.jar *.java
//

import u1.*;

public class MaxSequence {
	
	public static void main(String[] args){
		if(args.length == 0){
			System.out.println("usage: java MaxSequence Algorithm");
			System.exit(1);
		}
		
		try{
			Class c  = Class.forName(args[0]); // try to load argument class
			Object o = c.newInstance();		   // try to create an instance
			if(! (o instanceof IMaxSequence)){ //   and to cast it to IMaxSequence
				System.out.println("Class "+ args[0] +
					 " does not implement IMaxSequence");
				System.exit(1);
			}
			
			int n = 10; // start length
			double t0, t1;
			
			t0 = MaxSequenceTest.test((IMaxSequence)o, n); n *= 2;
			while(t0 < 10 && n < 10000000){
				t1 = MaxSequenceTest.test((IMaxSequence)o, n); n *= 2;
				System.out.println("      >>> ratio:  " + t1/t0);
				t0 = t1;
			}
		}
		catch(Exception e){
			System.out.println(e);
		}
	}
	
}

