package username.lists; import java.io.PrintWriter; /** * A simple test of simple lists. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class TestLinkedSimpleList { public static void main(String[] args) { LinkedSimpleList l = new LinkedSimpleList(); PrintWriter pen = new PrintWriter(System.out, true); pen.print("Testing isEmpty for an empty list: "); if (l.isEmpty()) { pen.println("OK"); } else { pen.println("FAILED"); } l.add("Sam"); pen.print("Testing isEmpty for a one-element list: "); if (l.isEmpty()) { pen.println("FAILED"); } else { pen.println("OK"); } l.delete(l.front()); pen.print("Testing whether delete made it empty again: "); if (l.isEmpty()) { pen.println("OK"); } else { pen.println("FAILED"); } l.add("Rebel"); pen.print("Testing whether add worked: "); if (l.get(l.front()).equals("Rebel")) { pen.println("OK"); } else { pen.println("FAILED"); } // Check whether front/isFront, rear/isLast work l.add("Sky"); pen.print("Testing front/isFront: "); if (l.isFirst(l.front())) { pen.println("OK"); } else { pen.println("FAILED"); } pen.print("Testing rear/isLast: "); if (l.isLast(l.rear())) { pen.println("OK"); } else { pen.println("FAILED"); } pen.print("Testing rear/isFront: "); if (l.isFirst(l.rear())) { pen.println("FAILED"); } else { pen.println("OK"); } pen.print("Testing front/isLast: "); if (l.isLast(l.front())) { pen.println("FAILED"); } else { pen.println("OK"); } // Try adding a buncha things and remove them all l.add("Banana"); l.add("Banana"); l.add("Banana"); l.removeAll(); pen.print("Testing whether we could remove many elements: "); if (l.isEmpty()) { pen.println("OK"); } else { pen.println("FAILED"); } } // main(String[]) } // TestLinkedSimpleList