Commit 4a9feeab authored by Younis's avatar Younis
Browse files

Add new file InsertionSortTest

parent 416020ad
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
public class InsertionSortTest {
@Test
public void testInsertionSort() {
int[] unsortedArray = {7, 98, 15, 38, 25, 0, 12, 8, 22, 83, 79, 77, 63, 56, 56, 2, 18, 21, 24, 28};
int[] expectedSortedArray = {0, 2, 7, 8, 12, 15, 18, 21, 22, 24, 25, 28, 38, 56, 56, 63, 77, 79, 83, 98};
// Test randomFill method
InsertionSort.randomFill(unsortedArray);
// Ensure the array is filled with random numbers between 0 and 99
for (int num : unsortedArray) {
assertTrue(num >= 0 && num < 100);
}
// Test insertionSort method
InsertionSort.insertionSort(unsortedArray);
// Ensure the array is sorted correctly
assertArrayEquals(expectedSortedArray, unsortedArray);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment