Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ void testBinarySearchEmptyArray() {
assertEquals(-1, binarySearch.find(array, key), "The element should not be found in an empty array.");
}

/**
* Test for binary search with a null array.
*/
@Test
void testBinarySearchNullArray() {
IterativeBinarySearch binarySearch = new IterativeBinarySearch();
Integer key = 1;
assertEquals(-1, binarySearch.find(null, key), "The element should not be found in a null array.");
}

/**
* Test for binary search with a null key.
*/
@Test
void testBinarySearchNullKey() {
IterativeBinarySearch binarySearch = new IterativeBinarySearch();
Integer[] array = {1, 2, 4, 8, 16};
assertEquals(-1, binarySearch.find(array, null), "A null search key should return -1.");
}

/**
* Test for binary search on a large array.
*/
Expand Down
Loading