package openlist; import junit.framework.TestCase; /** * A JUnit test case class. * Every method starting with the word "test" will be called when running * the test with JUnit. */ public class OpenlistTest extends TestCase { Openlist L; /** * A test method. */ public void testCons() { L = Openlist.cons("abc", Openlist.nil); assert( L != null ); } public void testFirst() { L = Openlist.cons("abc", Openlist.nil); assert( L.first().equals("abc") ); } public void testRest() { L = Openlist.cons("abc", Openlist.nil); assert( L.rest() == Openlist.nil ); } public void testIsEmpty() { L = Openlist.cons("abc", Openlist.nil); assert( !L.isEmpty() ); } public void testNonEmpty() { L = Openlist.cons("abc", Openlist.nil); assert( L.nonEmpty() ); } public void testList() { L = Openlist.list("a", "b", "c", "d"); assert( L.nonEmpty() ); assert( L.first().equals("a") ); assert( L.rest().first().equals("b") ); assert( L.rest().rest().first().equals("c") ); assert( L.rest().rest().rest().first().equals("d") ); assert( L.rest().rest().rest().rest().isEmpty() ); } public void testReverse() { L = Openlist.list("a", "b", "c", "d"); Openlist R = L.reverse(); assert( R.nonEmpty() ); assert( R.first().equals("d") ); assert( R.rest().first().equals("c") ); assert( R.rest().rest().first().equals("b") ); assert( R.rest().rest().rest().first().equals("a") ); assert( R.rest().rest().rest().rest().isEmpty() ); } public void testNonStaticCons() { L = Openlist.list("a", "b", "c", "d"); Openlist M = L.cons("z"); assert( M.first().equals("z")); } public void testToString() { L = Openlist.list("a", "b", "c", "d"); assert( L.toString().equals("(a b c d)") ); L = Openlist.list("a", Openlist.list("b", "c"), Openlist.nil, "d"); assert( L.toString().equals("(a (b c) () d)") ); } }