private List<Node> createNewNodes() { List<Node> nodes = new ArrayList<Node>(); int n = 5; for (int i = 0; i < n; i++) { Node node = new Node(); node.setValue("new node lit" + i); if (i < n - 1) { node.setNextIndex(i + 1); } nodes.add(node); } return nodes; }
// 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); }