Skip to content

Commit 695dd72

Browse files
committed
Fix
1 parent a9533d2 commit 695dd72

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

src/test/java/com/thealgorithms/searches/InterpolationSearchTest.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import org.junit.jupiter.api.Test;
6-
75
import java.util.stream.IntStream;
6+
import org.junit.jupiter.api.Test;
87

98
/**
109
* Unit tests for the InterpolationSearch class.
@@ -20,8 +19,7 @@ void testInterpolationSearchFound() {
2019
int[] array = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
2120
int key = 128;
2221
int expectedIndex = 7; // Index of the key in the array
23-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
24-
"The index of the found element should be 7.");
22+
assertEquals(expectedIndex, interpolationSearch.find(array, key), "The index of the found element should be 7.");
2523
}
2624

2725
/**
@@ -32,9 +30,7 @@ void testInterpolationSearchNotFound() {
3230
InterpolationSearch interpolationSearch = new InterpolationSearch();
3331
int[] array = {1, 2, 4, 8, 16};
3432
int key = 6; // Element not present in the array
35-
int expectedIndex = -1; // Key not found
36-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
37-
"The element should not be found in the array.");
33+
assertEquals(-1, interpolationSearch.find(array, key), "The element should not be found in the array.");
3834
}
3935

4036
/**
@@ -45,9 +41,7 @@ void testInterpolationSearchFirstElement() {
4541
InterpolationSearch interpolationSearch = new InterpolationSearch();
4642
int[] array = {1, 2, 4, 8, 16};
4743
int key = 1; // First element
48-
int expectedIndex = 0; // Index of the key in the array
49-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
50-
"The index of the first element should be 0.");
44+
assertEquals(0, interpolationSearch.find(array, key), "The index of the first element should be 0.");
5145
}
5246

5347
/**
@@ -58,9 +52,7 @@ void testInterpolationSearchSingleElementNotFound() {
5852
InterpolationSearch interpolationSearch = new InterpolationSearch();
5953
int[] array = {1};
6054
int key = 2; // Key not present
61-
int expectedIndex = -1; // Key not found
62-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
63-
"The element should not be found in the array.");
55+
assertEquals(-1, interpolationSearch.find(array, key), "The element should not be found in the array.");
6456
}
6557

6658
/**
@@ -71,9 +63,7 @@ void testInterpolationSearchEmptyArray() {
7163
InterpolationSearch interpolationSearch = new InterpolationSearch();
7264
int[] array = {}; // Empty array
7365
int key = 1; // Key not present
74-
int expectedIndex = -1; // Key not found
75-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
76-
"The element should not be found in an empty array.");
66+
assertEquals(-1, interpolationSearch.find(array, key), "The element should not be found in an empty array.");
7767
}
7868

7969
/**
@@ -84,9 +74,7 @@ void testInterpolationSearchLargeUniformArray() {
8474
InterpolationSearch interpolationSearch = new InterpolationSearch();
8575
int[] array = IntStream.range(0, 10000).map(i -> i * 2).toArray(); // Array from 0 to 19998, step 2
8676
int key = 9998; // Last even number in the array
87-
int expectedIndex = 4999; // Index of the last element
88-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
89-
"The index of the last element should be 4999.");
77+
assertEquals(4999, interpolationSearch.find(array, key), "The index of the last element should be 4999.");
9078
}
9179

9280
/**
@@ -97,8 +85,6 @@ void testInterpolationSearchLargeNonUniformArray() {
9785
InterpolationSearch interpolationSearch = new InterpolationSearch();
9886
int[] array = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144}; // Fibonacci numbers
9987
int key = 21; // Present in the array
100-
int expectedIndex = 6; // Index of the key in the array
101-
assertEquals(expectedIndex, interpolationSearch.find(array, key),
102-
"The index of the found element should be 6.");
88+
assertEquals(6, interpolationSearch.find(array, key), "The index of the found element should be 6.");
10389
}
10490
}

0 commit comments

Comments
 (0)