//small tester for VendMach
//be sure you understand all of the tests--this should help w/ review for if-else (decisions)
//as well as LOOPS and ARRAY manipulation
//obviously, also review for Ch 10: test design [Q: are these black box or white box tests?]

class VendTester {
    public static void main(String [] args) {
	VendMach vm = new VendMach(10);
	//test1: make sure I can't get a coke before machine is filled w/ cokes
	Coke shouldBeNull = vm.getCoke();
	if(shouldBeNull != null) {
	    System.out.println("ERROR: test1");
	}
	
	//test2: make sure you *can* get a coke after loading the machine (w/ the right expdate)
	vm.loadCokes("5/25/2005");
	Coke tempCoke = vm.getCoke();
	if(tempCoke ==null || !tempCoke.getExpDate().equals("5/25/2005")) {
	    System.out.println("ERROR: test2");
	}
	
	//test3: make sure you can *not* get a coke after all of the cokes are gone.
	//already got 1 coke, so get CAPACITY-1 more, after that the next coke should be null
	//
	for(int i=0; i<vm.getCapacity()-1; ++i) {
	    tempCoke = vm.getCoke();
	}
	//make sure we got the last coke
	if(tempCoke == null) {
	    System.out.println("ERROR: could not buy as many cokes as loaded");
	}
	tempCoke = vm.getCoke(); //should be null
	if(tempCoke !=null) {
	    System.out.println("ERROR: could get more cokes than loaded");
	}

	//test4: loads the machine, removes a coke, loads again w/ different expdate.
	//extracting cokes one by one should eventually yield 2 cokes in a row with
	//different expdates
	
	VendMach vm2 = new VendMach(12); 
	vm2.loadCokes("4/14/2005");
	//buy 2 cokes
	Coke tempCoke2 = vm2.getCoke();
	tempCoke2 = vm2.getCoke();
	//fill up again
	vm2.loadCokes("5/15/2005");
	//do the test
	//Note: this logic may be a little tricky when seen for the first time--may be useful
	//to practice code tracing (w/ memory diagrams) here.
	Coke coke1, coke2;
	String expDate1, expDate2;
	coke1 = vm2.getCoke(); 
	boolean success = false; //result of test
	for(int i=0; i<vm2.getCapacity()-1 && !success; ++i) {
	    coke2 = vm2.getCoke();
	    expDate1 = coke1.getExpDate();
	    expDate2 = coke2.getExpDate();
	    if(!expDate1.equals(expDate2)) {
		success = true;
	    }
	    //move down the array: coke1 becomes coke2, coke2 will be next coke (on 1st line of loop)
	    coke1 = coke2;
	}//for
	if(!success) {
	    System.out.println("ERROR: load() method resets all cokes instead of saving those still in machine.");
	}
    }//main	
}
