From 318cced06fe29db1dd23eee5564459dd6fee80a6 Mon Sep 17 00:00:00 2001 From: homnay1234 <99612060+homnay1234@users.noreply.github.com> Date: Sun, 20 Feb 2022 22:26:05 +0700 Subject: [PATCH 1/2] jUnit Test on Selection Sort I hope i can add a jUnit Test on Selection Sort for your Project --- TestSelectionSort | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 TestSelectionSort diff --git a/TestSelectionSort b/TestSelectionSort new file mode 100644 index 00000000..b98e7b86 --- /dev/null +++ b/TestSelectionSort @@ -0,0 +1,36 @@ +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class TestSort { + + SelectionSort selectionSort = new SelectionSort(); + @Test + public void tesInsertIntoSorted() { + int[] inputArr = new int[] {1,3,5}; + int[] inputResult = new int[] {1,3,5}; + selectionSort.selectionSort(inputArr); + assertArrayEquals(inputResult, inputArr); + } + + SelectionSort selectionSort2 = new SelectionSort(); + @Test + public void tesInsertIntoSorted2() { + int[] inputArr = new int[] {5,3,1}; + int[] inputResult = new int[] {1,3,5}; + selectionSort.selectionSort(inputArr); + assertArrayEquals(inputResult, inputArr); + } + + + SelectionSort selectionSort3 = new SelectionSort(); + @Test + public void tesInsertIntoSorted3() { + int[] inputArr = new int[] {4,5,3,2}; + int[] inputResult = new int[] {2,3,4,5}; + selectionSort.selectionSort(inputArr); + assertArrayEquals(inputResult, inputArr); + } + + +} From 9d226744461adde9ebf023b592cda6ec4268e9b6 Mon Sep 17 00:00:00 2001 From: homnay1234 <99612060+homnay1234@users.noreply.github.com> Date: Mon, 21 Feb 2022 19:08:26 +0700 Subject: [PATCH 2/2] Change code --- src/main/java/com/rampatra/searching/BinarySearch.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/rampatra/searching/BinarySearch.java b/src/main/java/com/rampatra/searching/BinarySearch.java index 26997658..dfd3e802 100644 --- a/src/main/java/com/rampatra/searching/BinarySearch.java +++ b/src/main/java/com/rampatra/searching/BinarySearch.java @@ -72,10 +72,6 @@ public static void main(String[] args) { System.out.println(binarySearch(new int[]{0, 2}, 0)); System.out.println(binarySearch(new int[]{0, 1, 2, 2, 2, 3, 3}, 2)); // doesn't return index of first occurrence System.out.println("---------"); - System.out.println(binarySearchNonRecursive(new int[]{0, 2}, 2)); - System.out.println(binarySearchNonRecursive(new int[]{0, 1, 2, 3}, 2)); - System.out.println(binarySearchNonRecursive(new int[]{0, 1, 2, 3}, 3)); - System.out.println(binarySearchNonRecursive(new int[]{0, 2}, 0)); - System.out.println(binarySearchNonRecursive(new int[]{0, 1, 2, 2, 2, 3, 3}, 2)); + } }