-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathTwoPointersTest.java
72 lines (60 loc) · 1.69 KB
/
TwoPointersTest.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.thealgorithms.others;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class TwoPointersTest {
@Test
void testPositivePairExists() {
int[] arr = {2, 6, 9, 22, 121};
int key = 28;
assertTrue(TwoPointers.isPairedSum(arr, key));
}
@Test
void testNegativePairExists() {
int[] arr = {-12, -1, 0, 8, 12};
int key = 0;
assertTrue(TwoPointers.isPairedSum(arr, key));
}
@Test
void testPairDoesNotExist() {
int[] arr = {0, 12, 12, 35, 152};
int key = 13;
assertFalse(TwoPointers.isPairedSum(arr, key));
}
@Test
void testNegativeSumPair() {
int[] arr = {-10, -3, 1, 2, 5, 9};
int key = -8;
assertTrue(TwoPointers.isPairedSum(arr, key));
}
@Test
void testPairDoesNotExistWithPositiveSum() {
int[] arr = {1, 2, 3, 4, 5};
int key = 10;
assertFalse(TwoPointers.isPairedSum(arr, key));
}
@Test
void testEmptyArray() {
int[] arr = {};
int key = 5;
assertFalse(TwoPointers.isPairedSum(arr, key));
}
@Test
void testSingleElementArray() {
int[] arr = {5};
int key = 5;
assertFalse(TwoPointers.isPairedSum(arr, key));
}
@Test
void testArrayWithDuplicateElements() {
int[] arr = {1, 1, 3, 5, 5};
int key = 6;
assertTrue(TwoPointers.isPairedSum(arr, key));
}
@Test
void testPairExistsAtEdges() {
int[] arr = {1, 3, 4, 7, 8};
int key = 9;
assertTrue(TwoPointers.isPairedSum(arr, key));
}
}