InsertionSortTest.java 843 Bytes
Newer Older
Younis's avatar
Younis committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
    }
}