UNB/ CS/ David Bremner/ teaching/ java/ SearchTest.java
public class SearchTest
{ 
  public final static int RANGE=1000000;
  public static void main(String[] args)


   { 
     StopWatch clock=new StopWatch();
     
     int increment, steps, sort,reps;
     int pos=-2;
     
     int target=500000;

     sort=Integer.parseInt(args[0]);
     increment=Integer.parseInt(args[1]);
     steps=Integer.parseInt(args[2]);
     reps=Integer.parseInt(args[3]);


     for (int len=increment; len <= steps*increment; len+=increment){
         int[] a = ArrayUtil.randomIntArray(len, RANGE);
         if (sort>1){
           clock.start();
         }

         if ( sort>0) {
           MergeSort.sort(a);
         }

         int found=0;
         if (sort < 2){
           clock.start();
         }
         for (int rep=0; rep<reps; rep++){
           target=(int)(Math.random()*RANGE);
           if (sort==0){
             pos=SequentialSearch.search(a,target);
           } else {
             pos=BinarySearch.search(a,target);
           }
           if (pos>=0) 
             found++;
         }
         clock.stop();
         System.out.println("#Found  "+found);
         System.out.println(len +"\t"+clock.getElapsedTime());
         clock.reset();
     }
   }
}
//
//