Advertisement
Guest User

t

a guest
Apr 24th, 2018
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public void testAddNewNode() {
  2.         String[] items = {"b","c","e"};
  3.         ArrayList<DNode> list = createList(items);
  4.         DNode head = list.get(0);
  5.  
  6.         DLSList testList= new DLSList();
  7.         testList.head= head;
  8.         testList.numNodes= items.length;
  9.         testList.lastVisited= testList.head; // Initialise testList to satisfy the class invariant
  10.        
  11.         // now prepare and add a node
  12.         DNode nodeToAdd= new DNode("d");
  13.         testList.addNewNode(nodeToAdd);
  14.        
  15.         String testArray1[]= {"b", "c", "d", "e" };
  16.  
  17.         DNode temp= testList.head;
  18.         for(int i=0; i< testArray1.length; i++){ // Checks the order of nodes starting from the first node
  19.             assertEquals(testArray1[i], temp.contents);
  20.             temp=temp.next;
  21.         }
  22.         assertEquals(testArray1.length, testList.numNodes);    
  23.        
  24.         nodeToAdd= new DNode("f");
  25.         testList.addNewNode(nodeToAdd);
  26.  
  27.         String testArray2[]= {"b", "c", "d", "e", "f" };
  28.         temp = testList.head;
  29.         for(int i=0; i< testArray2.length; i++){
  30.             assertEquals(testArray2[i], temp.contents);
  31.             temp=temp.next;
  32.         }
  33.         assertEquals(testArray2.length, testList.numNodes);    
  34.    
  35.         nodeToAdd= new DNode("a");
  36.         testList.addNewNode(nodeToAdd);
  37.  
  38.         String testArray3[]= {"a", "b", "c", "d", "e", "f" };
  39.         temp = testList.head;
  40.         for(int i=0; i< testArray3.length; i++){
  41.             assertEquals(testArray3[i], temp.contents);
  42.             temp=temp.next;
  43.         }
  44.         assertEquals(testArray3.length, testList.numNodes);
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement