/* * LinkedListTest.java * * Walter Goodwater * * CSc 300: Copyright Violations * */ public class LinkedListTest { public static String getListNames( LinkedList list ) { if( list.head.name == null ) { return " EMPTY!"; } String result = " "; LinkedListItr iter = new LinkedListItr( list.head, list.head.next ); while( iter.current != null ) { result += iter.previous.name; if( iter.current.next != null ) { result += " -> "; } iter.advance(); } return result; } public static void main( String args[] ) { LinkedList list = new LinkedList(); System.out.println( "Testing linked list....." ); /* Inserts */ System.out.println( "Testing Insert(): " ); System.out.println( " inserting: Bob, age 51" ); list.insert( "Bob", 51 ); System.out.println( " inserting: Tom, age 10" ); list.insert( "Tom", 10 ); System.out.println( " inserting: Sue, age 99" ); list.insert( "Sue", 99 ); System.out.println( " inserting: Dr. Turner, age 25" ); list.insert( "Dr. Turner", 25 ); /* Test Inserts */ System.out.println( " list should be:" ); System.out.println( " Sue -> Bob -> Dr. Turner -> Tom" ); System.out.println( " your list is: " ); String listNames = getListNames( list ); System.out.println( listNames ); if( listNames.equals(" Sue -> Bob -> Dr. Turner -> Tom") ) { System.out.println( " INSERTION PASSED!" ); } else { System.out.println( " INSERTION FAILED!" ); System.exit(-1); } /* Deletes */ System.out.println( "\n\nTesting delete():" ); System.out.println( " deleting: Bob " ); list.delete( "Bob" ); System.out.println( " list should be:" ); System.out.println( " Sue -> Dr. Turner -> Tom" ); System.out.println( " your list is:" ); listNames = getListNames( list ); System.out.println( listNames ); if( listNames.equals(" Sue -> Dr. Turner -> Tom") ) { System.out.println( " DELETE PASSED!" ); } else { System.out.println( " DELETE FAILED!" ); System.exit(-1); } System.out.println( " deleting: Dr. Turner " ); list.delete( "Dr. Turner" ); System.out.println( " list should be:" ); System.out.println( " Sue -> Tom" ); System.out.println( " your list is:" ); listNames = getListNames( list ); System.out.println( listNames ); if( listNames.equals(" Sue -> Tom") ) { System.out.println( " DELETE PASSED!" ); } else { System.out.println( " DELETE FAILED!" ); System.exit(-1); } System.out.println( " deleting: Sue & Tom " ); list.delete( "Sue" ); list.delete( "Tom" ); System.out.println( " list should be:" ); System.out.println( " EMPTY!" ); System.out.println( " your list is:" ); listNames = getListNames( list ); System.out.println( listNames ); if( listNames.equals(" EMPTY!") ) { System.out.println( " DELETE PASSED!" ); } else { System.out.println( " DELETE FAILED!" ); System.exit(-1); } } }