// CSE 143, Winter 2010, Marty Stepp // This client program creates an ArrayIntList object and calls several of // its methods to perform basic testing on the ArrayIntList class. // This third version of the program tests more methods such as toString, // as well as testing the StutterIntList class from Friday's lecture. public class TestArrayIntList { public static void main(String[] args) { StutterIntList stut = new StutterIntList(3); stut.add(7); // [7, 7, 7] stut.add(-1); // [7, 7, 7, -1, -1, -1] stut.add(2, 5); // [7, 7, 5, 5, 5, 7, -1, -1, -1] stut.remove(4); // [7, 7, 5, 5, 7, -1, -1, -1] System.out.println(stut); System.out.println(stut.getStretch()); // 3 // add 6 elements and print ArrayIntList list = new ArrayIntList(); // 10 // ArrayIntList list = new ArrayIntList(20); // 20 list.add(3); list.add(8); list.add(9); list.add(7); list.add(5); list.add(12); System.out.println(list); System.out.println(); // insert in the middle and print again list.add(3, 42); System.out.println(list); System.out.println(); // insert at the front and print again list.add(0, 999); System.out.println(list); System.out.println(); // add at the end and print again list.add(8, -1); System.out.println(list); System.out.println(); // add more than 10 total elements (resize) and print again list.add(943857); list.add(324768); System.out.println(list); System.out.println(); // System.out.println(list.get(18)); System.out.println("index of 42 is " + list.indexOf(42)); System.out.println("index of 12345 is " + list.indexOf(12345)); if (list.isEmpty()) { System.out.println("empty!"); } if (list.contains(42)) { System.out.println("42 is found in the list!"); } System.out.println(); System.out.println("remove tests:"); list.remove(4); System.out.println(list); System.out.println(); list.remove(0); System.out.println(list); System.out.println(); list.remove(list.size() - 1); System.out.println(list); System.out.println(); while (!list.isEmpty()) { list.remove(0); System.out.println(list); System.out.println(); } } }