forked from Hithomelabs/DSA_sheets
27 lines
999 B
Java
27 lines
999 B
Java
package com.hithomelabs.dsa.array.two_sum;
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
public class SolutionTest {
|
|
@Test
|
|
void testTwoSum() {
|
|
// Test case 1: nums = [2, 7, 11, 15], target = 9
|
|
int[] nums1 = {2, 7, 11, 15};
|
|
int target1 = 9;
|
|
int[] expected1 = {0, 1}; // indices of the numbers that add up to target
|
|
assertArrayEquals(expected1, new HashMapSolution().solve(nums1, target1));
|
|
|
|
// Test case 2: nums = [3, 2, 4], target = 6
|
|
int[] nums2 = {3, 2, 4};
|
|
int target2 = 6;
|
|
int[] expected2 = {1, 2}; // indices of the numbers that add up to target
|
|
assertArrayEquals(expected2, new HashMapSolution().solve(nums2, target2));
|
|
|
|
// Test case 3: nums = [3, 3], target = 6
|
|
int[] nums3 = {3, 3};
|
|
int target3 = 6;
|
|
int[] expected3 = {0, 1}; // indices of the numbers that add up to target
|
|
assertArrayEquals(expected3, new HashMapSolution().solve(nums3, target3));
|
|
}
|
|
}
|