import java.util.Random; /** This is the final version of a class that tests the Graph methods of Assignment 3, CS 155, Fall 2007, San Jose State University */ public class A3 { // for random generation of test data private static Random r = new Random(1); /** Tests several all-pairs methods on a graph and prints the solutions @param g the graph */ private static void testAndPrintAllAlgorithms(Graph g) { Graph allPairs = g.naiveAllPairs(); System.out.println(allPairs); allPairs = g.floydAllPairs(); System.out.println(allPairs); allPairs = g.gtAllPairs(); System.out.println(allPairs); allPairs = g.bfAllPairs(); System.out.println(allPairs); } /** Tests several all-pairs methods on a graph. Compares the solutions and prints the results. Prints the time required to compute each of the solutions @param g the graph */ private static void testAllAlgorithms(Graph g) { int NUMBER_OF_TESTS = 4; Graph[] result = new Graph[NUMBER_OF_TESTS]; Long currentTime = System.currentTimeMillis(); result[0] = g.naiveAllPairs(); Long elapsedTime1 = System.currentTimeMillis() - currentTime; currentTime = System.currentTimeMillis(); result[1] = g.floydAllPairs(); Long elapsedTime2 = System.currentTimeMillis() - currentTime; currentTime = System.currentTimeMillis(); result[2] = g.gtAllPairs(); Long elapsedTime3 = System.currentTimeMillis() - currentTime; currentTime = System.currentTimeMillis(); result[3] = g.bfAllPairs(); Long elapsedTime4 = System.currentTimeMillis() - currentTime; System.out.println(" naive Floyd GT BF "); for (int i=0; i