import lrs.*; import lrs.visitor.*; /** * Tests a few visitors. * @author D. X. Nguyen * @since 10/10/01 */ public class TestVisitors { public void testIntegerList(IAlgo algo, Object inp) { System.out.println("Testing " + algo.getClass() + " with input " + inp); LRStruct lon = new LRStruct(); lon.insertFront(new Integer(-4)); System.out.println("Before: " + lon); lon.execute(algo, inp); System.out.println("After: " + lon); lon.insertFront(new Integer(17)); System.out.println("Before: " + lon); lon.execute(algo, inp); System.out.println("After: " + lon); lon.insertFront(new Integer(-23)); lon.insertFront(new Integer(10)); System.out.println("Before: " + lon); lon.execute(algo, inp); System.out.println("After: " + lon); lon.insertFront(new Integer(-30)); lon.insertFront(new Integer(48)); System.out.println("Before: " + lon); lon.execute(algo, inp); System.out.println("After: " + lon); lon.insertFront(new Integer(0)); lon.insertFront(new Integer(5)); lon.insertFront(new Integer(100)); lon.insertFront(new Integer(-20)); lon.insertFront(new Integer(-39)); System.out.println("Before: " + lon); lon.execute(algo, inp); System.out.println("After: " + lon); System.out.println(); } public void testListOfLists(IAlgo algo, Object inp) { System.out.println("Testing " + algo.getClass() + " with input " + inp); LRStruct LoL = new LRStruct(); LRStruct lon1 = new LRStruct(); lon1.insertFront(new Double(-4)); LoL.insertFront(lon1); lon1 = new LRStruct(); lon1.insertFront(new Double(17)); lon1.insertFront(new Double(-23)); lon1.insertFront(new Double(10)); LoL.insertFront(lon1); lon1 = new LRStruct(); LoL.insertFront(lon1); lon1 = new LRStruct(); lon1.insertFront(new Double(-30)); lon1.insertFront(new Double(48)); LoL.insertFront(lon1); lon1 = new LRStruct(); lon1.insertFront(new Double(0)); lon1.insertFront(new Double(5)); lon1.insertFront(new Double(100)); lon1.insertFront(new Double(-20)); lon1.insertFront(new Double(-39)); LoL.insertFront(lon1); System.out.println("Before: " + LoL); LoL.execute(algo, inp); System.out.println("After: " + LoL); System.out.println(); } public void test() { testIntegerList(AddPairs.Singleton, null); testIntegerList(FilterN.Singleton, new Integer(2)); testIntegerList(ModN.Singleton, new Integer(5)); testListOfLists(ReplaceWithAverage.Singleton, null); } public static void main(String[] args) { new TestVisitors().test(); } }