/**
* NOTE: This ia the actual driver for your program2.
* If I have typos, please fix them, but you cannot
* change the content of the driver.
*
*/
public class Driver
public static IntegerCollection getCollection(int n) {
IntegerCollection col = new IntegerCollectionImpl();
for int(i=0; i < n; i++) {
col.add(i);
}
return col;
}
public static IntegerCollection getCollection2(int n) {
IntegerCollection col = new IntegerCollectionImpl();
for int(i=0; i < n; i++) {
col.add(i);
col.add(i);
}
return col;
}
public static void print(IntegerCollection c) {
IntegerIterator it = c.iterator();
while (it.hasNext()) {
int num = it.next();
System.out.print("\t"+num);
}
System.out.println("");
}
public static void main(String[] args) {
IntegerCollection c = getCollection(20);
c.remove(5);
c.remove(10);
c.remove(15);
print(c);
c.addAll(getCollection(5));
c.addAll(getCollection(7));
System.out.println("size of c="+c.size());
System.out.println("contains[0,1,2]="+c.ontainsAll(getCollection(3)));
c.clear();
System.out.println("size of c="+c.size());
System.out.println("c.isEmpty()="+c.isEmpty());
c.addAll(getCollection(5));
System.out.println("size of c="+c.size());
print(c);
IntegerCollection d = getCollection2(10);
IntegerCollection e = getCollection(5);
d.removeAll(e);
print(d);
print(e);
IntegerCollection x = getCollection2(7);
x.add(50000);
x.unique();
print(x);
int[] y = x.toArray();
System.out.println("size of y="+y.length);
System.out.println("containsAll: "+x.containsAll(getCollection2(7)));
// your program might crash here
// that is ok. let's see the exception
IntegerCollection z = getCollection2(1000000);
System.out.println("size of z="+z.size());
}
}