import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Arrays; import java.util.Random; public class Tester { static public class Pair { private X fst; private Y snd; public Pair(X fst, Y snd) {this.fst=fst; this.snd=snd;} public X getFirst() { return fst; } public Y getSecond() { return snd; } public void setFirst(X fst) { this.fst=fst; } public void setSecond(Y snd) { this.snd=snd; } } public static double compare(Pair,int[]> P) // return the number of points, max: 0.4 { print(P); SortedList L=P.getFirst(); int[] A=P.getSecond(); double points=0.0; if (A.length==L.size()) points += 0.05; if (isSorted(L)) points += 0.05; int count=0; for (int i=0; iA.length-3) points += 0.2-0.05*(A.length-count); // test count() int idcount=1; count=0; int maxcount=0; for (int i=1; imaxcount-3) points += 0.1-0.025*(maxcount-count); return points; } public static Pair,int[]> generate(int size,Random generator,int minindex,int maxindex) // for minindex and maxindex: non-positive values mean size()+1-index { SortedList L=new SortedList(); int A[]=new int[size]; int mini,maxi; for (int i=0; i,int[]> P; P=new Pair , int[]>(L,A); return P; } private static boolean isSorted(SortedList L) { for (int i=1; i 0) return false; return true; } private static void print(Pair,int[]> P) { System.out.println("Sorted List:"); for (int i=1; i<=P.getFirst().size(); i++) System.out.print(" "+P.getFirst().get(i)); System.out.println(); System.out.println("Sorted array:"); for (int i=0; i,int[]> P; System.out.println("Test 1."); // test adding at the beginning try { P=generate(10,R,1,1); points += compare(P); } catch (Exception e) { // no exception expected System.out.println("Unexpected exception"+e); } System.out.println("Test 2."); // test adding at the end try { P=generate(20,R,0,0); points += compare(P); } catch (Exception e) { // no exception expected System.out.println("Unexpected exception"+e); } System.out.println("Test 3."); // test adding at random positions try { P=generate(30,R,1,0); points += compare(P); } catch (Exception e) { // no exception expected System.out.println("Unexpected exception"+e); } System.out.println("Test 4."); // test remove at position try { P=generate(30,R,1,-1); P.getFirst().remove(10); int A[]=new int[P.getSecond().length-1]; for (int i=0, j=0; i