// 6 public void testGetFirstNodeFromList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); int first = 0; Node expectedNode = list.get(first); Node actualNode = list.first(); assertEquals(expectedNode, actualNode); }
// 7 public void testGetLastNodeFromList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); int last = list.size() - 1; Node expectedNode = list.get(last); Node actualNode = list.last(); assertEquals(expectedNode, actualNode); }
// 8 public void testGetBeforeNodeFromList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); Node node = list.get(2); Node expectedNode = list.get(1); Node actualNode = list.before(node); assertEquals(expectedNode, actualNode); }
// 4 public void testInsertAfterIndexN() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); int size = list.size(); int n = 2; Node node = new Node(); node.setValue("Node 1"); node.setNextIndex(n + 1); list.insertAfter(node, n); assertTrue(size < list.size()); Node nodeInsert = list.get(n); assertEquals(node.getValue(), nodeInsert.getValue()); assertEquals(node.getNextIndex(), nodeInsert.getNextIndex()); assertTrue(nodeInsert == node); }
// 5 public void testDeleteFromList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); int size = list.size(); int position = 2; Node node = list.get(position); list.delete(node); assertTrue(size > list.size()); assertTrue(node != list.get(position)); }
// 3 public void testGetSizeOfLinkList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); assertTrue(nodes.size() == list.size()); }
// 2 public void testCreateNewLinkListWithObjectList() { List<Node> nodes = createNewNodes(); SingleLinkedList list = new SingleLinkedList(nodes); assertEquals(nodes, list.getList()); }
// 1 public void testCreateNewLinkListWithEmptyList() { List<Node> nodes = new ArrayList<Node>(); SingleLinkedList linkedList = new SingleLinkedList(nodes); assertTrue(linkedList.getList().isEmpty()); }