Skip to content

Commit 1814e2b

Browse files
author
alx
committed
Refactoring tests for BinaryInsertionSort according to SortingAlgorithmTest
1 parent 4651c1e commit 1814e2b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
package com.thealgorithms.sorts;
22

3+
/**
4+
* BinaryInsertionSort class implements the SortAlgorithm interface using the binary insertion sort technique.
5+
* Binary Insertion Sort improves upon the simple insertion sort by using binary search to find the appropriate
6+
* location to insert the new element, reducing the number of comparisons in the insertion step.
7+
*/
38
public class BinaryInsertionSort implements SortAlgorithm {
49

5-
// Binary Insertion Sort method
10+
/**
11+
* Sorts the given array using the Binary Insertion Sort algorithm.
12+
*
13+
* @param <T> the type of elements in the array, which must implement the Comparable interface
14+
* @param array the array to be sorted
15+
* @return the sorted array
16+
*/
617
public <T extends Comparable<T>> T[] sort(T[] array) {
718
for (int i = 1; i < array.length; i++) {
819
T temp = array[i];

src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

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

7-
class BinaryInsertionSortTest {
7+
class BinaryInsertionSortTest extends SortingAlgorithmTest {
8+
private final BinaryInsertionSort binaryInsertionSort = new BinaryInsertionSort();
89

9-
BinaryInsertionSort binaryInsertionSort = new BinaryInsertionSort();
10+
@Override
11+
SortAlgorithm getSortAlgorithm() {
12+
return binaryInsertionSort;
13+
}
1014

1115
@Test
1216
// valid test case

0 commit comments

Comments
 (0)