forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListCycleTest.java
More file actions
52 lines (44 loc) · 1.29 KB
/
LinkedListCycleTest.java
File metadata and controls
52 lines (44 loc) · 1.29 KB
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
package com.examplehub.leetcode.easy;
import static org.junit.jupiter.api.Assertions.*;
import com.examplehub.leetcode.ListNode;
import org.junit.jupiter.api.Test;
class LinkedListCycleTest {
@Test
void testSolution1() {
ListNode head = new ListNode(3);
ListNode node2 = new ListNode(2);
ListNode node3 = new ListNode(0);
ListNode node4 = new ListNode(4);
head.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node2;
assertTrue(LinkedListCycle.solution1(head));
head = new ListNode(1);
node2 = new ListNode(2);
head.next = node2;
node2.next = head;
assertTrue(LinkedListCycle.solution1(head));
head = new ListNode(1);
assertFalse(LinkedListCycle.solution1(head));
}
@Test
void testSolution2() {
ListNode head = new ListNode(3);
ListNode node2 = new ListNode(2);
ListNode node3 = new ListNode(0);
ListNode node4 = new ListNode(4);
head.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node2;
assertTrue(LinkedListCycle.solution2(head));
head = new ListNode(1);
node2 = new ListNode(2);
head.next = node2;
node2.next = head;
assertTrue(LinkedListCycle.solution2(head));
head = new ListNode(1);
assertFalse(LinkedListCycle.solution2(head));
}
}