|
@@ -0,0 +1,61 @@
|
|
|
|
|
+package leetcode.p142;
|
|
|
|
|
+
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
|
+import org.junit.runner.RunWith;
|
|
|
|
|
+import org.junit.runners.Parameterized;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ProjectName: LeetCode
|
|
|
|
|
+ * @FileName: SolutionTest
|
|
|
|
|
+ * @Author: 杨逸
|
|
|
|
|
+ * @Data:2026/3/7 14:50
|
|
|
|
|
+ * @Description:
|
|
|
|
|
+ */
|
|
|
|
|
+@RunWith(Parameterized.class)
|
|
|
|
|
+public class SolutionTest {
|
|
|
|
|
+ public static final Solution solution = new Solution();
|
|
|
|
|
+ private ListNode head;
|
|
|
|
|
+ private ListNode expected;
|
|
|
|
|
+
|
|
|
|
|
+ public SolutionTest(ListNode head, ListNode expected) {
|
|
|
|
|
+ this.head = head;
|
|
|
|
|
+ this.expected = expected;
|
|
|
|
|
+ }
|
|
|
|
|
+ @Parameterized.Parameters
|
|
|
|
|
+ public static Collection<Object[]> data() {
|
|
|
|
|
+ ArrayList<Object[]> list = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ list.add(new Object[]{head, node2});
|
|
|
|
|
+
|
|
|
|
|
+ head = new ListNode(1);
|
|
|
|
|
+ node2 = new ListNode(2);
|
|
|
|
|
+ head.next = node2;
|
|
|
|
|
+ node2.next = head;
|
|
|
|
|
+ list.add(new Object[]{head, head});
|
|
|
|
|
+
|
|
|
|
|
+ head = new ListNode(1);
|
|
|
|
|
+ list.add(new Object[]{head, null});
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void detectCycle() {
|
|
|
|
|
+ ListNode listNode = solution.detectCycle(head);
|
|
|
|
|
+ assertEquals(expected, listNode);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|