Testing Interpolation Search Algorithm Implementation in Algorithms Repository
This test suite validates the InterpolationSearch algorithm implementation using JUnit’s parameterized testing capabilities. The tests verify both successful search scenarios and edge cases where values are not found in the sorted array.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
williamfiset/algorithms
src/test/java/com/williamfiset/algorithms/search/InterpolationSearchTest.java
package com.williamfiset.algorithms.search;
import static com.google.common.truth.Truth.assertThat;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;
public class InterpolationSearchTest {
private static Arguments[] inputs() {
return new Arguments[] {
Arguments.of(2, 2), Arguments.of(5, 5), Arguments.of(-1, -1), Arguments.of(8, -1)
};
}
@ParameterizedTest(name = "Search value: {0}, Expected index: {1}")
@MethodSource("inputs")
public void testCoverage(int val, int expected) {
int[] arr = {0, 1, 2, 3, 4, 5};
int index = InterpolationSearch.interpolationSearch(arr, val);
assertThat(index).isEqualTo(expected);
}
}