-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedListTest.java
81 lines (59 loc) · 2.06 KB
/
LinkedListTest.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package week4.assignment2;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
class LinkedListTest {
private static LinkedList linkedList = new LinkedList();
@Test
void add() {
//given
ListNode head = new ListNode();
//when
linkedList.add(head, new ListNode(1), 0);
linkedList.add(head, new ListNode(2), 1);
linkedList.add(head, new ListNode(3), 2);
//then( 추가한 노드의 총 사이즈가 맞는지)
assertThat(linkedList.size(head)).isEqualTo(3);
//when
linkedList.add(head, new ListNode(4), 3);
linkedList.add(head, new ListNode(5), 2); //★
ListNode node = linkedList.get(head, 2);
//then (★ : 추가한 노드의 데이터가 순서에 맞게 잘들어갔는지
assertThat(node.getData()).isEqualTo(5);
/*StringBuilder sb2 = linkedList.getStringBuilder(head);
System.out.println(sb2.toString());
assertThat(linkedList.size(head)).isEqualTo(3);*/
}
@Test
void remove() {
//given
ListNode head = new ListNode();
//when
linkedList.add(head, new ListNode(1), 0);
linkedList.add(head, new ListNode(2), 1);
linkedList.add(head, new ListNode(3), 2);
linkedList.add(head, new ListNode(4), 3);
linkedList.add(head, new ListNode(5), 4);
linkedList.remove(head, 2);
//then(노드 제거후 노드의 총 개수가 맞는지)
assertThat(linkedList.size(head)).isEqualTo(4);
/* StringBuilder sb2 = linkedList.getStringBuilder(head);
System.out.println(sb2.toString());
assertThat(linkedList.size(head)).isEqualTo(3);*/
}
@Test
void contains() {
//given
ListNode head = new ListNode();
ListNode listNode = new ListNode(1);
ListNode listNode2 = new ListNode(2);
ListNode listNode3 = new ListNode(3);
//when
linkedList.add(head, listNode, 0);
linkedList.add(head, listNode2, 1);
linkedList.add(head, listNode3, 2);
boolean flag = linkedList.contains(head, listNode2);
//then
assertThat(flag).isEqualTo(true);
}
}