-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListCycleTest.java
More file actions
32 lines (29 loc) · 1.09 KB
/
LinkedListCycleTest.java
File metadata and controls
32 lines (29 loc) · 1.09 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
import org.example.helpers.ListNode;
import org.example.problems.linked_list_cycle.Solution;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
public class LinkedListCycleTest {
private static Stream<Arguments> provideCases() {
ListNode tail = new ListNode(-4);
ListNode second = new ListNode(2, new ListNode(0, tail));
tail.next = second;
ListNode cycled1 = new ListNode(3, second);
ListNode tail2 = new ListNode(2);
ListNode cycled2 = new ListNode(1, tail2);
tail2.next = cycled2;
return Stream.of(
Arguments.of(cycled1, true),
Arguments.of(cycled2, true),
Arguments.of(new ListNode(1), false)
);
}
@ParameterizedTest
@MethodSource("provideCases")
public void test(ListNode head, boolean expected) {
Solution s = new Solution();
Assertions.assertSame(expected, s.hasCycle(head));
}
}