Leetcode150/dsa/src/test/java/com/hithomelabs/dsa/array/search_in_rotated_sorted_array/SolutionTest.java

40 lines
1.2 KiB
Java

package com.hithomelabs.dsa.array.search_in_rotated_sorted_array;
public class SolutionTest {
@Test
void testSolve() {
Solution solution = new Solution();
// Test case 1: Normal case with rotation
int[] nums1 = {4, 5, 6, 7, 0, 1, 2};
int target1 = 0;
assertEquals(4, solution.solve(nums1, target1));
// Test case 2: Target not present
int[] nums2 = {4, 5, 6, 7, 0, 1, 2};
int target2 = 3;
assertEquals(-1, solution.solve(nums2, target2));
// Test case 3: Array with one element (target present)
int[] nums3 = {1};
int target3 = 1;
assertEquals(0, solution.solve(nums3, target3));
// Test case 4: Array with one element (target not present)
int[] nums4 = {1};
int target4 = 0;
assertEquals(-1, solution.solve(nums4, target4));
// Test case 5: Array is rotated at the pivot
int[] nums5 = {3, 1};
int target5 = 1;
assertEquals(1, solution.solve(nums5, target5));
// Test case 6: Array is not rotated
int[] nums6 = {1, 2, 3, 4, 5};
int target6 = 3;
assertEquals(2, solution.solve(nums6, target6));
}
}