Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void testAddNewNode() {
- String[] items = {"b","c","e"};
- ArrayList<DNode> list = createList(items);
- DNode head = list.get(0);
- DLSList testList= new DLSList();
- testList.head= head;
- testList.numNodes= items.length;
- testList.lastVisited= testList.head; // Initialise testList to satisfy the class invariant
- // now prepare and add a node
- DNode nodeToAdd= new DNode("d");
- testList.addNewNode(nodeToAdd);
- String testArray1[]= {"b", "c", "d", "e" };
- DNode temp= testList.head;
- for(int i=0; i< testArray1.length; i++){ // Checks the order of nodes starting from the first node
- assertEquals(testArray1[i], temp.contents);
- temp=temp.next;
- }
- assertEquals(testArray1.length, testList.numNodes);
- nodeToAdd= new DNode("f");
- testList.addNewNode(nodeToAdd);
- String testArray2[]= {"b", "c", "d", "e", "f" };
- temp = testList.head;
- for(int i=0; i< testArray2.length; i++){
- assertEquals(testArray2[i], temp.contents);
- temp=temp.next;
- }
- assertEquals(testArray2.length, testList.numNodes);
- nodeToAdd= new DNode("a");
- testList.addNewNode(nodeToAdd);
- String testArray3[]= {"a", "b", "c", "d", "e", "f" };
- temp = testList.head;
- for(int i=0; i< testArray3.length; i++){
- assertEquals(testArray3[i], temp.contents);
- temp=temp.next;
- }
- assertEquals(testArray3.length, testList.numNodes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement