// CSE 373, Winter 2013, Marty Stepp // This client program tests the HashSet class. public class Lecture10Main { public static void main(String[] args) { HashSet set = new HashSet(); // test add System.out.println("test add():"); for (int n : new int[] {42, 29, 42, 17, 112, -9, 17, 82, 53}) { set.add(n); System.out.println("after adding " + n + ", set = " + set + ", size = " + set.size()); set.debug(); } System.out.println(); // test contains System.out.println("test contains():"); for (int n : new int[] {42, 29, 42, 17, 112, -9, 17, 82, 53, 55, 182, -91, 888}) { System.out.println(set + " contains " + n + "? " + set.contains(n)); set.debug(); } System.out.println(); // test remove System.out.println("test remove():"); for (int n : new int[] {55, 42, 182, 17, -91, 82}) { set.remove(n); System.out.println("after removing " + n + ", set = " + set + ", size = " + set.size() + ", contains " + n + "? " + set.contains(n)); set.debug(); } System.out.println(); // test add after remove int newValue = 22; set.add(newValue); System.out.println("after adding " + newValue + ", set = " + set + ", size = " + set.size() + ", contains " + newValue + "? " + set.contains(newValue)); set.debug(); // test array resizing System.out.println("test add() with resize:"); for (int n : new int[] {33, 56, 22, 19, 41, 104, -2, 75, 75, 22, 984, -777, 66, 33, 90210, 44444}) { set.add(n); System.out.println("after adding " + n + ", set = " + set + ", size = " + set.size()); set.debug(); } } }