From 4a9feeabe88bb53884f823862cbc0457c9305885 Mon Sep 17 00:00:00 2001 From: Younis <nida.younis@hft-stuttgart.de> Date: Tue, 24 Sep 2024 12:46:49 +0000 Subject: [PATCH] Add new file InsertionSortTest --- InsertionSortTest.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 InsertionSortTest.java diff --git a/InsertionSortTest.java b/InsertionSortTest.java new file mode 100644 index 0000000..ab173fe --- /dev/null +++ b/InsertionSortTest.java @@ -0,0 +1,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); + } +} -- GitLab