import java.io.FileWriter; import java.io.FileReader; import java.io.IOException; import java.util.Vector; import java.util.Random; import Minor.P3.DS.Point; import Minor.P3.DS.Lewis; // Run this with a command-line argument (any argument) to run with random data: // // java testDriver -prof // // Run without a command-line argument and this will read a seed value from the // file Seed.txt; you can save the seed value from a Curator report in Seed.txt // to replicate a test that was performed there. // // This file goes in the src direcory of your Eclipse project and the actual test // harness Lewis.java goes in the Minor/P3/DS subdirectory. public class testDriver { static int xMin = 0; // world is [0, 2^15] on all sides static int xMax = 1 << 15; static int yMin = 0; static int yMax = 1 << 15; static Vector data; static Vector seps; // holds subregion boundaries static Random source; static boolean profMode = false; public static void main(String[] args) throws IOException { if ( args.length > 0 ) { profMode = true; } seps = new Vector(); computePartition(10); String summaryName = "Summary.txt"; if ( profMode ) summaryName = "prof" + summaryName; FileWriter summary = new FileWriter(summaryName); data = new Vector(); generatePoints(); Lewis louie = new Lewis(xMin, xMax, yMin, yMax, data, source, profMode); int numTestsRun = 0; checkTreeInitialization(louie, summary); ++numTestsRun; checkInsertion(louie, summary); ++numTestsRun; checkDeletion(louie, summary); ++numTestsRun; checkRegionSearch(louie, summary); ++numTestsRun; summary.write(louie.writePoints(0) + " Completed " + numTestsRun + " tests.\n" ); summary.close(); } private static void checkTreeInitialization(Lewis louie, FileWriter summary) throws IOException { try { louie.checkTreeInitialization(); } catch ( Exception e ) { summary.write(louie.writePoints(0) + " OOPS: caught an exception from call to checkTreeInitialization().\n"); } summary.write(louie.writePoints(0) + " Completed test of quadtree initialization.\n"); } private static void checkInsertion(Lewis louie, FileWriter summary) throws IOException { try { louie.checkInsertion(); } catch ( Exception e ) { summary.write(louie.writePoints(0) + " OOPS: caught an exception from call to checkInsertion().\n"); } summary.write(louie.writePoints(0) + " Completed test of quadtree insertion.\n"); } private static void checkDeletion(Lewis louie, FileWriter summary) throws IOException { try { louie.checkDeletion(); } catch ( Exception e ) { summary.write(louie.writePoints(0) + " OOPS: caught an exception from call to checkDeletion().\n"); } summary.write(louie.writePoints(0) + " Completed test of quadtree deletion.\n"); } private static void checkRegionSearch(Lewis louie, FileWriter summary) throws IOException { try { louie.checkRegionSearch(); } catch ( Exception e ) { summary.write(louie.writePoints(0) + " OOPS: caught an exception from call to checkRegionSearch().\n"); } summary.write(louie.writePoints(0) + " Completed test of quadtree region search.\n"); } private static void generatePoints() throws IOException { long Seed = 0; if ( profMode ) { Seed = System.currentTimeMillis(); FileWriter s = new FileWriter("Seed.txt"); s.write(new Long(Seed).toString()); s.close(); } else { FileReader s = new FileReader("Seed.txt"); char[] c = new char[20]; int nDigits = s.read(c, 0, 15); //c[nDigits] = '\0'; String x = new String(c, 0, nDigits); Seed = Long.parseLong(x); s.close(); } source = new Random( Seed ); int numPts = 25; // 10 + Math.abs(source.nextInt()) % 21; int pt = 0; while ( pt < numPts ) { long x = Math.abs(source.nextInt()) % xMax; long y = Math.abs(source.nextInt()) % yMax; if ( seps.contains(x) ) { ++x; } if ( seps.contains(y) ) { ++y; } Point nxt = new Point(x, y); if ( !data.contains(nxt) ) { ++pt; data.add(nxt); } } } private static void computePartition(int Divisions) { int numParts = 1 << Divisions; int Step = (xMax - xMin) / numParts; for (int lvl = 0; lvl <= numParts; lvl++) { long x = xMin + lvl * Step; seps.add( x ); //System.out.println(x); } } }