/** The test class for the IntList composte classes with insertion sort. */ class IntListTest extends TestCase { /** Tests the insert method. */ void testInsert() { IntList e = new EmptyIntList(); // '() IntList l1 = e.cons(17); // '(17) IntList l2 = l1.cons(5); // '(5 17) IntList l3 = e.cons(5); // '(5) IntList l4 = l3.cons(5); // '(5 5) IntList l5 = l3.cons(17); // '(17 5) IntList l6 = l5.cons(-5).cons(100).cons(50); // '(50 100 -5 17 5) IntList l7 = e.cons(100).cons(50).cons(17).cons(5).cons(-5); // '(-5 5 17 50 100) IntList l8 = e.cons(100).cons(50).cons(20). cons(17).cons(5).cons(-5); // '(-5 5 17 50 100) assertEquals("empty insert test", l1, e.insert(17)); assertEquals("pre insert test", l2, l1.insert(5)); assertEquals("post insert test", l2, l3.insert(17)); assertEquals("equals insert test", l4, l3.insert(5)); assertEquals("five elts insert test", l8, l7.insert(20)); } /** Tests the sort method. */ void testSort() { IntList e = new EmptyIntList(); // '() IntList l1 = e.cons(17); // '(17) IntList l2 = l1.cons(5); // '(5 17) IntList l3 = e.cons(5); // '(5) IntList l4 = l3.cons(5); // '(5 5) IntList l5 = l3.cons(17); // '(17 5) IntList l6 = l5.cons(-5).cons(100).cons(50); // '(50 100 -5 17 5) IntList l7 = e.cons(100).cons(50).cons(17).cons(5).cons(-5); // '(-5 5 17 50 100) assertEquals("empty sort test", e, e.sort()); assertEquals("one elt test", l1, l1.sort()); assertEquals("two elts in order test", l2, l2.sort()); assertEquals("two elts out of order test", l2, l5.sort()); assertEquals("two equal elts test", l4, l4.sort()); assertEquals("five elts test", l7, l6.sort()); } }