/** Source code example for "A Practical Introduction to Data Structures and Algorithm Analysis, 3rd Edition (Java)" by Clifford A. Shaffer Copyright 2008-2011 by Clifford A. Shaffer */ /** A JUnit test class for the payroll dictionary. */ import java.io.*; public class SortedTest extends junit.framework.TestCase { private SortedList L1; private SortedList L2; private SortedList L3; /** * This method is automatically called once before each test case method, * so that all the variables are cleanly initialized for each test. */ public void setUp() { L1 = new SAList(); L2 = new SAList(15); L3 = new SAList(); } // Return true if "k" matches the key for an element in list "L", // false otherwise public static E find(SortedList L, Key k ) { Key itkey; for (L.moveToStart(); L.currPos()"); L1.moveToStart(); assertEquals(find(L1, 3), null); assertEquals(L1.toString(), "< 5 9 39 | >"); L1.moveToStart(); L1val = find(L1, 9); assertEquals(L1val, new Integer(9)); L1val = find(L1, 5); assertEquals(L1val, new Integer(5)); assertEquals(L1.length(), 3); L2.insert("X", "X"); assertEquals(L2.toString(), "< | X >"); L2.insert("A", "A"); assertEquals(L2.toString(), "< | A X >"); L2.insert("Y", "Y"); assertEquals(L2.toString(), "< A X | Y >"); String temp2I = L2.remove(); assertEquals(temp2I, "Y"); assertEquals(L2.toString(), "< A X | >"); } }