Skip to content

Commit a7ba4ed

Browse files
author
Fahham29
committed
Fix: call static method correctly in test file
1 parent 4b444f4 commit a7ba4ed

File tree

1 file changed

+17
-48
lines changed

1 file changed

+17
-48
lines changed

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

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,60 @@
44

55
import org.junit.jupiter.api.Test;
66

7-
/**
8-
* Unit tests for the JumpSearch class.
9-
*/
107
class JumpSearchTest {
118

12-
/**
13-
* Test for finding an element present in the array.
14-
*/
159
@Test
1610
void testJumpSearchFound() {
17-
JumpSearch jumpSearch = new JumpSearch();
1811
Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
19-
Integer key = 5; // Element to find
20-
assertEquals(5, jumpSearch.find(array, key), "The index of the found element should be 5.");
12+
Integer key = 5;
13+
assertEquals(5, JumpSearch.find(array, key));
2114
}
2215

23-
/**
24-
* Test for finding the first element in the array.
25-
*/
2616
@Test
2717
void testJumpSearchFirstElement() {
28-
JumpSearch jumpSearch = new JumpSearch();
2918
Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
30-
Integer key = 0; // First element
31-
assertEquals(0, jumpSearch.find(array, key), "The index of the first element should be 0.");
19+
Integer key = 0;
20+
assertEquals(0, JumpSearch.find(array, key));
3221
}
3322

34-
/**
35-
* Test for finding the last element in the array.
36-
*/
3723
@Test
3824
void testJumpSearchLastElement() {
39-
JumpSearch jumpSearch = new JumpSearch();
4025
Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
41-
Integer key = 10; // Last element
42-
assertEquals(10, jumpSearch.find(array, key), "The index of the last element should be 10.");
26+
Integer key = 10;
27+
assertEquals(10, JumpSearch.find(array, key));
4328
}
4429

45-
/**
46-
* Test for finding an element not present in the array.
47-
*/
4830
@Test
4931
void testJumpSearchNotFound() {
50-
JumpSearch jumpSearch = new JumpSearch();
5132
Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
52-
Integer key = -1; // Element not in the array
53-
assertEquals(-1, jumpSearch.find(array, key), "The element should not be found in the array.");
33+
Integer key = -1;
34+
assertEquals(-1, JumpSearch.find(array, key));
5435
}
5536

56-
/**
57-
* Test for finding an element in an empty array.
58-
*/
5937
@Test
6038
void testJumpSearchEmptyArray() {
61-
JumpSearch jumpSearch = new JumpSearch();
62-
Integer[] array = {}; // Empty array
63-
Integer key = 1; // Key not present
64-
assertEquals(-1, jumpSearch.find(array, key), "The element should not be found in an empty array.");
39+
Integer[] array = {};
40+
Integer key = 1;
41+
assertEquals(-1, JumpSearch.find(array, key));
6542
}
6643

67-
/**
68-
* Test for finding an element in a large array.
69-
*/
7044
@Test
7145
void testJumpSearchLargeArray() {
72-
JumpSearch jumpSearch = new JumpSearch();
7346
Integer[] array = new Integer[1000];
7447
for (int i = 0; i < array.length; i++) {
75-
array[i] = i * 2; // Fill the array with even numbers
48+
array[i] = i * 2;
7649
}
77-
Integer key = 256; // Present in the array
78-
assertEquals(128, jumpSearch.find(array, key), "The index of the found element should be 128.");
50+
Integer key = 256;
51+
assertEquals(128, JumpSearch.find(array, key));
7952
}
8053

81-
/**
82-
* Test for finding an element in a large array when it is not present.
83-
*/
8454
@Test
8555
void testJumpSearchLargeArrayNotFound() {
86-
JumpSearch jumpSearch = new JumpSearch();
8756
Integer[] array = new Integer[1000];
8857
for (int i = 0; i < array.length; i++) {
89-
array[i] = i * 2; // Fill the array with even numbers
58+
array[i] = i * 2;
9059
}
91-
Integer key = 999; // Key not present
92-
assertEquals(-1, jumpSearch.find(array, key), "The element should not be found in the array.");
60+
Integer key = 999;
61+
assertEquals(-1, JumpSearch.find(array, key));
9362
}
9463
}

0 commit comments

Comments
 (0)