import java.io.*;

/** Perform some basic tests on A1Driver, Space, and Point
 */

public class A1Test {
    public static A1Driver a1;

    /** Run the tests.
     */
    public static void main(String[] args) throws IOException {
		
        test2();
	test3();
	test4();
	test5();
	test1();

    }

    /** Test reading individual points from standard input, and printing
     * the space in order of the distance from the viewpoint.
     */
    public static void test1() throws IOException {
	System.out.println("**********");
	System.out.println("* Test 1");
	System.out.println("**********");
	a1 = new A1Driver();
	a1.initSpace();

	// remap standard input so that it is coming from the file.
	System.setIn(new FileInputStream("p1.1"));
	System.out.println("* readPoint() - 4 5 6");
	a1.readPoint();
	System.setIn(new FileInputStream("p1.2"));
	System.out.println("* readPoint() - 6 5 4");
	a1.readPoint();
	System.setIn(new FileInputStream("p1.3"));
	System.out.println("* readPoint() - 10 4 10");
	a1.readPoint();
	System.setIn(new FileInputStream("v1"));
	System.out.println("* readViewPoint() - 0 0 0");
	a1.readViewPoint();
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("");
    }

    /** Test the load method in A1Driver, and test that changing the view 
     * point results in a correct reordering of the points in space.
     */
    public static void test2() throws IOException {
	System.out.println("**********");
	System.out.println("* Test 2");
	System.out.println("**********");
	a1 = new A1Driver();
	a1.initSpace();
	System.setIn(new FileInputStream("v1"));
	a1.load("pd1");
	System.out.println("* readViewPoint() - 0 0 0");
	a1.readViewPoint();
	System.out.println("* printSpace");
	a1.printSpace();
	System.setIn(new FileInputStream("v2"));
	System.out.println("* readViewPoint() - 20 20 20");
	a1.readViewPoint();
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("");
    }

    /** Test the get method from A1Driver
     */
    public static void test3() throws IOException {
	System.out.println("**********");
	System.out.println("* Test 3");
	System.out.println("**********");
	a1 = new A1Driver();
	a1.initSpace();
	System.setIn(new FileInputStream("v1"));
	System.out.println("* load - pd2");
	a1.load("pd2");
	System.out.println("* readViewPoint() - 0 0 0");
	a1.readViewPoint();
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("* get(0)");
	a1.get(0);
	System.out.println("* get(1)");
	a1.get(1);
	System.out.println("* get(6)");
	a1.get(6);
	System.out.println("");
    }

    /** Test the samePlane method in each dimension.
     */
    public static void test4() throws IOException {
	System.out.println("**********");
	System.out.println("* Test 4");
	System.out.println("**********");
	a1 = new A1Driver();
	a1.initSpace();
	System.setIn(new FileInputStream("v3"));
	System.out.println("* load - pd2");
	a1.load("pd2");
	System.out.println("* readViewPoint() - 1 2 4");
	a1.readViewPoint();
	System.out.println("* samePlane(0)");
	a1.samePlane(0);
	System.out.println("* samePlane(1)");
	a1.samePlane(1);
	System.out.println("* samePlane(2)");
	a1.samePlane(2);
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("");
    }

    /** Test the write method in A1Driver by writing to a file and reloading 
     * the points.
     */
    public static void test5() throws IOException {
	System.out.println("**********");
	System.out.println("* Test 5");
	System.out.println("**********");
	a1 = new A1Driver();
	a1.initSpace();
	System.setIn(new FileInputStream("v3"));
	System.out.println("* load - pd1");
	a1.load("pd1");
	System.out.println("* readViewPoint() - 0 0 0");
	a1.readViewPoint();
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("* write - pdout");
	a1.write("pdout");
	System.out.println("* load - pdout");
	a1.load("pdout");
	System.out.println("* printSpace");
	a1.printSpace();
	System.out.println("");
    }
}
