// File: ftest2.C
//
// Testing the FArray class

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include "farray.h"

main(int argc, char *argv[]) {
   int reps=0, seed=0 ;
   int i, r, count ;
   DATA key ;

   if (argc != 4) {
      cerr << "Usage: a.out reps seed fname" << endl ;
      exit(1) ;
   }

   reps = atoi(argv[1]) ;
   seed = atoi(argv[2]) ;

   if (reps <= 0 || seed <= 0) {
      cerr << "Bad size or seed" << endl ;
      exit(1) ;
   }

   srand48(seed) ;

   FArray A(argv[3]) ;

   count = 0 ;
   for (i = 0 ; i< reps ; i++) {
      key = (DATA) drand48() ;
      r = A.bsearch(key) ;

      if (r >= 0) {
         cout << "Found: key = " << key
              << " A[" << r << "] = " << A[r] << endl ;
         count++ ;
      }
   }
   cout << "Number of hits: " << count << endl ;
}
