forked from gardncl/elements-of-programming-interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteNodeTest.java
36 lines (26 loc) · 998 Bytes
/
DeleteNodeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import org.junit.Test;
public class DeleteNodeTest {
private ListNode<Integer> expected;
private ListNode<Integer> listToDeleteFrom;
private ListNode<Integer> node;
@Test
public void deleteNode1() {
node = new ListNode<>(10);
expected = LinkedListUtil.createLinkedList(1, 2, 3, 4, 5);
listToDeleteFrom = LinkedListUtil.createLinkedList(1, 2, 3, 4, 5);
listToDeleteFrom.get(3).insertAfter(node);
test(expected, listToDeleteFrom, node);
}
@Test
public void deleteNode2() {
node = new ListNode<>(10);
node.insertAfter(new ListNode<>(1));
expected = LinkedListUtil.createLinkedList(1);
listToDeleteFrom = node;
test(expected, listToDeleteFrom, node);
}
private void test(ListNode<Integer> expected, ListNode<Integer> listToDeleteFrom, ListNode<Integer> node) {
DeleteNode.deleteNode(node);
LinkedListUtil.assertSameList(expected, listToDeleteFrom);
}
}