|
|
@@ -0,0 +1,46 @@
|
|
|
+package leetcode.p35;
|
|
|
+
|
|
|
+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/9 15:15
|
|
|
+ * @Description:
|
|
|
+ */
|
|
|
+@RunWith(Parameterized.class)
|
|
|
+public class SolutionTest {
|
|
|
+ public static final Solution solution = new Solution();
|
|
|
+ private final int[] nums;
|
|
|
+ private final int target;
|
|
|
+ private final int expected;
|
|
|
+
|
|
|
+ public SolutionTest(int[] nums, int target, int expected) {
|
|
|
+ this.nums = nums;
|
|
|
+ this.target = target;
|
|
|
+ this.expected = expected;
|
|
|
+ }
|
|
|
+ @Parameterized.Parameters
|
|
|
+ public static Collection<Object[]> data() {
|
|
|
+ return Arrays.asList(new Object[][]{
|
|
|
+ {new int[]{1,3,5,6},5,2},
|
|
|
+ {new int[]{1,3,5,6},2,1},
|
|
|
+ {new int[]{1,3,5,6},7,4},
|
|
|
+ {new int[]{1,3,5,6},0,0},
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void searchInsert() {
|
|
|
+ int result = solution.searchInsert(nums, target);
|
|
|
+ assertEquals(expected, result);
|
|
|
+ }
|
|
|
+}
|