package playingWithLists;

import java.util.Iterator;

public class MyLinkedListTest {

	public static void main(String[] args) {
		
		Integer[] someIntegers = {1, 2, 3, 4};
		
		MyLinkedList<Integer> aList = 
			new MyLinkedList<Integer>(someIntegers);
		
		/* TEST 1: print out list */
		
		System.out.println("TEST 1: printing list [1,2,3,4]");
		System.out.println(aList);
	
		/* TEST 2: get */
		
		System.out.println("TEST 2: get third element ");
		System.out.println(aList.get(2));
		
		/* TEST 3: set */
		
		System.out.println("TEST 3: set second element to '7'");
		aList.set(1,7);
		System.out.println(aList);
		
		/* TEST 4: add */
		
		System.out.println("TEST 4: add element '42' at 4th position");
		aList.add(3,42);
		System.out.println(aList);
		
		/* TEST 5: remove */
		
		System.out.println("TEST 5: remove second element");
		aList.remove(1);
		System.out.println(aList);
		
		/* TEST 6: iterator */
		System.out.println("TEST 6: iterate over and print list [1,2,3,...,12]");
		
		Integer [] manyIntegers = {1,2,3,4,5,6,7,8,9,10,11,12};
		MyLinkedList<Integer> longList = new MyLinkedList<Integer>(manyIntegers);
		
		for (Integer x : longList) {
			System.out.println(x);
		}
		
		/* TEST 7: iterator remove*/
		System.out.println("TEST 7: iterate and remove all even elements from list [1,2,3,...,12]");
	
		Iterator<Integer> it = longList.iterator();
		while (it.hasNext()) {
			Integer current = it.next();
			if (current % 2 == 0)
				it.remove();
		}
		System.out.println(longList);


		/* TEST 8: remove without ever calling next */
		System.out.println("TEST 8: remove without ever calling next ");
		
		Iterator<Integer> it2 = longList.iterator();
		try {
		    it2.remove();
		    System.out.println("Error: no IllegalStateException thrown");
		} catch (IllegalStateException e) {
		    System.out.println("successfully caught IllegalStateException");
		}


		/* TEST 9: remove two times after next */
		System.out.println("TEST 9: remove two times after next");
		
		Iterator<Integer> it3 = longList.iterator();
		it3.next();
		try {
		    it3.remove();
		    it3.remove();
		    System.out.println("Error: no IllegalStateException thrown");
		} catch (IllegalStateException e) {
		    System.out.println("successfully caught IllegalStateException");
		}

		
	}

}
