Skip to content

Commit b190c6f

Browse files
committed
FourSum Problem Done
1 parent 718cf03 commit b190c6f

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/test/java/com/thealgorithms/misc/FourSumProblemTest.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,57 @@ public void testFourSum2_withDuplicateSecondIndex() {
131131
int[] nums = {2, 2, 2, 2, 2, 0, 0};
132132
int target = 4;
133133
List<List<Integer>> result = solver.fourSum2(nums, target);
134-
134+
135135
assertEquals(1, result.size()); // Expect only one quadruplet
136136
assertTrue(result.contains(List.of(0, 0, 2, 2))); // The only valid quadruplet
137137
}
138138

139+
@Test
140+
public void testFourSum1_withNullArray() {
141+
FourSumProblem solver = new FourSumProblem();
142+
143+
// Case with null input array
144+
int[] nums = null;
145+
int target = 0;
146+
List<List<Integer>> result = solver.fourSum1(nums, target);
147+
148+
assertEquals(0, result.size()); // Expect no quadruplets
149+
}
150+
151+
@Test
152+
public void testFourSum2_withNullArray() {
153+
FourSumProblem solver = new FourSumProblem();
154+
155+
// Case with null input array
156+
int[] nums = null;
157+
int target = 0;
158+
List<List<Integer>> result = solver.fourSum2(nums, target);
159+
160+
assertEquals(0, result.size()); // Expect no quadruplets
161+
}
162+
163+
@Test
164+
public void testFourSum1_withLessThanFourElements() {
165+
FourSumProblem solver = new FourSumProblem();
166+
167+
// Case with fewer than four elements
168+
int[] nums = {1, 2, 3}; // Only 3 elements
169+
int target = 0;
170+
List<List<Integer>> result = solver.fourSum1(nums, target);
171+
172+
assertEquals(0, result.size()); // Expect no quadruplets
173+
}
174+
175+
@Test
176+
public void testFourSum2_withLessThanFourElements() {
177+
FourSumProblem solver = new FourSumProblem();
178+
179+
// Case with fewer than four elements
180+
int[] nums = {1, 2, 3}; // Only 3 elements
181+
int target = 0;
182+
List<List<Integer>> result = solver.fourSum2(nums, target);
183+
184+
assertEquals(0, result.size()); // Expect no quadruplets
185+
}
186+
139187
}

0 commit comments

Comments
 (0)