|
|
@@ -0,0 +1,45 @@
|
|
|
+package leetcode.p219;
|
|
|
+
|
|
|
+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/8 17:02
|
|
|
+ * @Description:
|
|
|
+ */
|
|
|
+@RunWith(Parameterized.class)
|
|
|
+public class SolutionTest {
|
|
|
+ public static final Solution solution = new Solution();
|
|
|
+ private int[] nums;
|
|
|
+ private int k;
|
|
|
+ private boolean expected;
|
|
|
+
|
|
|
+ public SolutionTest(int[] nums, int k, boolean expected) {
|
|
|
+ this.nums = nums;
|
|
|
+ this.k = k;
|
|
|
+ this.expected = expected;
|
|
|
+ }
|
|
|
+ @Parameterized.Parameters
|
|
|
+ public static Collection<Object[]> data(){
|
|
|
+ return Arrays.asList(new Object[][]{
|
|
|
+ {new int[]{1,2,3,1},3,true},
|
|
|
+ {new int[]{1,0,1,1},1,true},
|
|
|
+ {new int[]{1,2,3,1,2,3},2,false},
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void containsNearbyDuplicate() {
|
|
|
+ boolean result = solution.containsNearbyDuplicate(nums, k);
|
|
|
+ assertEquals(expected,result);
|
|
|
+ }
|
|
|
+}
|