|
@@ -0,0 +1,48 @@
|
|
|
|
|
+package leetcode.p41;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
|
+import org.junit.runner.RunWith;
|
|
|
|
|
+import org.junit.runners.Parameterized;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ProjectName: LeetCode
|
|
|
|
|
+ * @FileName: SolutionTest
|
|
|
|
|
+ * @Author: 杨逸
|
|
|
|
|
+ * @Data:2026/3/6 22:16
|
|
|
|
|
+ * @Description:
|
|
|
|
|
+ */
|
|
|
|
|
+@RunWith(Parameterized.class)
|
|
|
|
|
+public class SolutionTest {
|
|
|
|
|
+ private static final Solution solution = new Solution();
|
|
|
|
|
+ //1.参数载体
|
|
|
|
|
+ private int[] nums;
|
|
|
|
|
+ private int expected;
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 构造函数:JUnit 4 会自动将 @Parameters 中的每一组数据注入
|
|
|
|
|
+ public SolutionTest(int[] nums, int expected) {
|
|
|
|
|
+ this.nums = nums;
|
|
|
|
|
+ this.expected = expected;
|
|
|
|
|
+ }
|
|
|
|
|
+ //3.提供数据
|
|
|
|
|
+ @Parameterized.Parameters(name = "{index}: input={0}, expected={1}")
|
|
|
|
|
+ public static Collection<Object[]> data() {
|
|
|
|
|
+ return Arrays.asList(new Object[][] {
|
|
|
|
|
+ { new int[]{1, 2, 0}, 3 }, // 基础情况
|
|
|
|
|
+ { new int[]{3, 4, -1, 1}, 2 }, // 含负数
|
|
|
|
|
+ { new int[]{7, 8, 9, 11, 12}, 1 }, // 缺失1
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void firstMissingPositive() {
|
|
|
|
|
+ int result = solution.firstMissingPositive(nums);
|
|
|
|
|
+ assertEquals("输入 " + Arrays.toString(nums) + " 时结果错误",
|
|
|
|
|
+ expected, result);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|