|
4 | 4 |
|
5 | 5 | import org.junit.jupiter.api.Test;
|
6 | 6 |
|
7 |
| -/** |
8 |
| - * Unit tests for the JumpSearch class. |
9 |
| - */ |
10 | 7 | class JumpSearchTest {
|
11 | 8 |
|
12 |
| - /** |
13 |
| - * Test for finding an element present in the array. |
14 |
| - */ |
15 | 9 | @Test
|
16 | 10 | void testJumpSearchFound() {
|
17 |
| - JumpSearch jumpSearch = new JumpSearch(); |
18 | 11 | 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)); |
21 | 14 | }
|
22 | 15 |
|
23 |
| - /** |
24 |
| - * Test for finding the first element in the array. |
25 |
| - */ |
26 | 16 | @Test
|
27 | 17 | void testJumpSearchFirstElement() {
|
28 |
| - JumpSearch jumpSearch = new JumpSearch(); |
29 | 18 | 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)); |
32 | 21 | }
|
33 | 22 |
|
34 |
| - /** |
35 |
| - * Test for finding the last element in the array. |
36 |
| - */ |
37 | 23 | @Test
|
38 | 24 | void testJumpSearchLastElement() {
|
39 |
| - JumpSearch jumpSearch = new JumpSearch(); |
40 | 25 | 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)); |
43 | 28 | }
|
44 | 29 |
|
45 |
| - /** |
46 |
| - * Test for finding an element not present in the array. |
47 |
| - */ |
48 | 30 | @Test
|
49 | 31 | void testJumpSearchNotFound() {
|
50 |
| - JumpSearch jumpSearch = new JumpSearch(); |
51 | 32 | 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)); |
54 | 35 | }
|
55 | 36 |
|
56 |
| - /** |
57 |
| - * Test for finding an element in an empty array. |
58 |
| - */ |
59 | 37 | @Test
|
60 | 38 | 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)); |
65 | 42 | }
|
66 | 43 |
|
67 |
| - /** |
68 |
| - * Test for finding an element in a large array. |
69 |
| - */ |
70 | 44 | @Test
|
71 | 45 | void testJumpSearchLargeArray() {
|
72 |
| - JumpSearch jumpSearch = new JumpSearch(); |
73 | 46 | Integer[] array = new Integer[1000];
|
74 | 47 | for (int i = 0; i < array.length; i++) {
|
75 |
| - array[i] = i * 2; // Fill the array with even numbers |
| 48 | + array[i] = i * 2; |
76 | 49 | }
|
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)); |
79 | 52 | }
|
80 | 53 |
|
81 |
| - /** |
82 |
| - * Test for finding an element in a large array when it is not present. |
83 |
| - */ |
84 | 54 | @Test
|
85 | 55 | void testJumpSearchLargeArrayNotFound() {
|
86 |
| - JumpSearch jumpSearch = new JumpSearch(); |
87 | 56 | Integer[] array = new Integer[1000];
|
88 | 57 | for (int i = 0; i < array.length; i++) {
|
89 |
| - array[i] = i * 2; // Fill the array with even numbers |
| 58 | + array[i] = i * 2; |
90 | 59 | }
|
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)); |
93 | 62 | }
|
94 | 63 | }
|
0 commit comments