package listFW.test; import junit.framework.TestCase; import listFW.*; import listFW.visitor.*; import listFW.factory.*; import fp.*; /** * Testing reversing a list using FoldL. * @author DXN */ public class Test_FoldLIList extends TestCase { IListFactory fac = CompositeListFactory.Singleton; ILambda cons = new Cons(fac); IListAlgo algo = new FoldLIList(cons); IList mt = fac.makeEmptyList(); public void testEmpty() { assertEquals("Reverse Empty list", "()", mt.execute(algo, mt).toString()); } public void testNonEmpty() { IList L = fac.makeNEList("a", mt); assertEquals("Reverse (a)", "(a)", L.execute(algo, mt).toString()); L = fac.makeNEList("b", L); assertEquals("Reverse ( b, a)", "(a, b)", L.execute(algo, mt).toString()); L = fac.makeNEList("c", L); assertEquals("Reverse ( c, b, a)", "(a, b, c)", L.execute(algo, mt).toString()); } }