From 77bd1213e73f44ef2560948aee10cc5fa1f8e8dc Mon Sep 17 00:00:00 2001 From: pushkar Date: Sun, 6 Jul 2025 10:51:04 +0530 Subject: [PATCH 1/3] Added test cases for sorting algorithms --- .../sorts/AdaptiveMergeSortTest.java | 85 ++++++++++++++++++ .../com/thealgorithms/sorts/BogoSortTest.java | 80 +++++++++++++++++ .../thealgorithms/sorts/BubbleSortTest.java | 81 +++++++++++++++++ .../thealgorithms/sorts/GnomeSortTest.java | 86 +++++++++++++++++++ .../sorts/InsertionSortTest.java | 80 +++++++++++++++++ .../com/thealgorithms/sorts/SlowSortTest.java | 80 +++++++++++++++++ 6 files changed, 492 insertions(+) diff --git a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java index 9d94b165d81b..2d2ca894d01f 100644 --- a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.api.Test; +import java.util.Objects; + public class AdaptiveMergeSortTest { @Test @@ -50,4 +52,87 @@ public void testSortSingleElement() { Integer[] result = adaptiveMergeSort.sort(input); assertArrayEquals(expected, result); } + + @Test + public void testSortAlreadySortedArray() { + AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = adaptiveMergeSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortReversedSortedArray() { + AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = adaptiveMergeSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortAllEqualArray() { + AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = adaptiveMergeSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortMixedCaseStrings() { + AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = adaptiveMergeSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + public void testSortCustomObjects() { + AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = adaptiveMergeSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } } diff --git a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java index 3ebfb7a305b0..bfd5b13c13ba 100644 --- a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.api.Test; +import java.util.Objects; + public class BogoSortTest { private BogoSort bogoSort = new BogoSort(); @@ -63,4 +65,82 @@ public void bogoSortDuplicateStringArray() { String[] expectedOutput = {"a", "b", "b", "c", "d", "d", "h", "s"}; assertArrayEquals(outputArray, expectedOutput); } + + @Test + public void bogoSortAlreadySortedArray() { + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = bogoSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bogoSortReversedSortedArray() { + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = bogoSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bogoSortAllEqualArray() { + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = bogoSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bogoSortMixedCaseStrings() { + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = bogoSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + public void bogoSortCustomObjects() { + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = bogoSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } } diff --git a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java index 8690a3f5435c..902c942a10d4 100644 --- a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.api.Test; +import java.util.Objects; + /** * @author Aitor Fidalgo (https://github.com/aitorfi) * @see BubbleSort @@ -91,4 +93,83 @@ public void bubbleSortStringArray() { }; assertArrayEquals(outputArray, expectedOutput); } + + @Test + public void bubbleSortAlreadySortedArray() { + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = bubbleSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bubbleSortReversedSortedArray() { + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = bubbleSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bubbleSortAllEqualArray() { + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = bubbleSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void bubbleSortMixedCaseStrings() { + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = bubbleSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + public void bubbleSortCustomObjects() { + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = bubbleSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + } diff --git a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java index d86546472580..294a5100c03a 100644 --- a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java @@ -1,10 +1,13 @@ package com.thealgorithms.sorts; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.Objects; + public class GnomeSortTest { private GnomeSort gnomeSort = new GnomeSort(); @@ -79,4 +82,87 @@ public void gnomeSortDuplicateStringArray() { gnomeSort.sort(inputArray); assertThat(inputArray).isEqualTo(expectedOutput); } + + @Test + @DisplayName("GnomeSort for sorted Array") + public void testSortAlreadySortedArray() { + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = gnomeSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + @DisplayName("GnomeSort for reversed sorted Array") + public void testSortReversedSortedArray() { + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = gnomeSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + @DisplayName("GnomeSort for All equal Array") + public void testSortAllEqualArray() { + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = gnomeSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + @DisplayName("GnomeSort String Array with mixed cases") + public void testSortMixedCaseStrings() { + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = gnomeSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + @DisplayName("GnomeSort Custom Object Array") + public void testSortCustomObjects() { + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = gnomeSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } } diff --git a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java index 78744973355d..b88263fbd93f 100644 --- a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java @@ -3,8 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Objects; import java.util.function.Function; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; class InsertionSortTest { @@ -111,4 +113,82 @@ private void testWithRandomArray(Function sortAlgorithm) { Double[] sorted = sortAlgorithm.apply(array); assertTrue(SortUtils.isSorted(sorted)); } + + @Test + public void testSortAlreadySortedArray() { + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = insertionSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortReversedSortedArray() { + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = insertionSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortAllEqualArray() { + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = insertionSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortMixedCaseStrings() { + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = insertionSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + public void testSortCustomObjects() { + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = insertionSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } } diff --git a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java index d4d9eaa1c275..bc5517c4ee91 100644 --- a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.api.Test; +import java.util.Objects; + /** * @author Rebecca Velez (https://github.com/rebeccavelez) * @see SlowSort @@ -76,4 +78,82 @@ public void slowSortStringSymbolArray() { String[] expectedOutput = {"(a", "(b", ")", "a", "au", "auk", "auk", "bhy", "cba", "cba", "cbf", "á", "ó"}; assertArrayEquals(outputArray, expectedOutput); } + + @Test + public void testSortAlreadySortedArray() { + Integer[] inputArray = {-12, -6, -3, 0, 2, 2, 13, 46}; + Integer[] outputArray = slowSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortReversedSortedArray() { + Integer[] inputArray = {46, 13, 2, 2, 0, -3, -6, -12}; + Integer[] outputArray = slowSort.sort(inputArray); + Integer[] expectedOutput = {-12, -6, -3, 0, 2, 2, 13, 46}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortAllEqualArray() { + Integer[] inputArray = {2, 2, 2, 2, 2}; + Integer[] outputArray = slowSort.sort(inputArray); + Integer[] expectedOutput = {2, 2, 2, 2, 2}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void testSortMixedCaseStrings() { + String[] inputArray = {"banana", "Apple", "apple", "Banana"}; + String[] expectedOutput = {"Apple", "Banana", "apple", "banana"}; + String[] outputArray = slowSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } + + /** + * Custom Comparable class for testing. + **/ + static class Person implements Comparable { + String name; + int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public int compareTo(Person o) { + return Integer.compare(this.age, o.age); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Person)) return false; + Person p = (Person) o; + return this.name.equals(p.name) && this.age == p.age; + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } + + @Test + public void testSortCustomObjects() { + Person[] inputArray = { + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + }; + Person[] expectedOutput = { + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), + }; + Person[] outputArray = slowSort.sort(inputArray); + assertArrayEquals(expectedOutput, outputArray); + } } From 853d2e46f0ec334220fb2e94a08473ec5b181715 Mon Sep 17 00:00:00 2001 From: pushkar Date: Sun, 6 Jul 2025 11:37:26 +0530 Subject: [PATCH 2/3] Formatted the newly added tests using clang-format --- .../sorts/AdaptiveMergeSortTest.java | 15 +++++++-------- .../com/thealgorithms/sorts/BogoSortTest.java | 15 +++++++-------- .../com/thealgorithms/sorts/BubbleSortTest.java | 16 +++++++--------- .../com/thealgorithms/sorts/GnomeSortTest.java | 15 +++++++-------- .../thealgorithms/sorts/InsertionSortTest.java | 12 ++++++------ .../com/thealgorithms/sorts/SlowSortTest.java | 15 +++++++-------- 6 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java index 2d2ca894d01f..3656c4ce5a2d 100644 --- a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java @@ -2,9 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import org.junit.jupiter.api.Test; - import java.util.Objects; +import org.junit.jupiter.api.Test; public class AdaptiveMergeSortTest { @@ -123,14 +122,14 @@ public int hashCode() { public void testSortCustomObjects() { AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort(); Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = adaptiveMergeSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); diff --git a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java index bfd5b13c13ba..a4536c1ce1be 100644 --- a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java @@ -2,9 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import org.junit.jupiter.api.Test; - import java.util.Objects; +import org.junit.jupiter.api.Test; public class BogoSortTest { @@ -131,14 +130,14 @@ public int hashCode() { @Test public void bogoSortCustomObjects() { Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = bogoSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); diff --git a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java index 902c942a10d4..97672829ec2e 100644 --- a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java @@ -2,9 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import org.junit.jupiter.api.Test; - import java.util.Objects; +import org.junit.jupiter.api.Test; /** * @author Aitor Fidalgo (https://github.com/aitorfi) @@ -159,17 +158,16 @@ public int hashCode() { @Test public void bubbleSortCustomObjects() { Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = bubbleSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); } - } diff --git a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java index 294a5100c03a..35a73d36fd10 100644 --- a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java @@ -3,11 +3,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - public class GnomeSortTest { private GnomeSort gnomeSort = new GnomeSort(); @@ -153,14 +152,14 @@ public int hashCode() { @DisplayName("GnomeSort Custom Object Array") public void testSortCustomObjects() { Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = gnomeSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); diff --git a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java index b88263fbd93f..b901e3c542fb 100644 --- a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java @@ -179,14 +179,14 @@ public int hashCode() { @Test public void testSortCustomObjects() { Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = insertionSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); diff --git a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java index bc5517c4ee91..a2d3cae15a61 100644 --- a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java @@ -2,9 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import org.junit.jupiter.api.Test; - import java.util.Objects; +import org.junit.jupiter.api.Test; /** * @author Rebecca Velez (https://github.com/rebeccavelez) @@ -144,14 +143,14 @@ public int hashCode() { @Test public void testSortCustomObjects() { Person[] inputArray = { - new Person("Alice", 32), - new Person("Bob", 25), - new Person("Charlie", 28), + new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), }; Person[] expectedOutput = { - new Person("Bob", 25), - new Person("Charlie", 28), - new Person("Alice", 32), + new Person("Bob", 25), + new Person("Charlie", 28), + new Person("Alice", 32), }; Person[] outputArray = slowSort.sort(inputArray); assertArrayEquals(expectedOutput, outputArray); From 2a9554a51a0b578d1b62902722221884179b0a18 Mon Sep 17 00:00:00 2001 From: pushkar Date: Sun, 6 Jul 2025 19:07:09 +0530 Subject: [PATCH 3/3] Resolved the checkstyle violations in the testcase classes --- .../java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java | 4 +++- src/test/java/com/thealgorithms/sorts/BogoSortTest.java | 4 +++- src/test/java/com/thealgorithms/sorts/BubbleSortTest.java | 4 +++- src/test/java/com/thealgorithms/sorts/GnomeSortTest.java | 4 +++- src/test/java/com/thealgorithms/sorts/InsertionSortTest.java | 5 +++-- src/test/java/com/thealgorithms/sorts/SlowSortTest.java | 4 +++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java index 3656c4ce5a2d..c43aad7989eb 100644 --- a/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/AdaptiveMergeSortTest.java @@ -107,7 +107,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } diff --git a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java index a4536c1ce1be..7fcf51396615 100644 --- a/src/test/java/com/thealgorithms/sorts/BogoSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BogoSortTest.java @@ -116,7 +116,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } diff --git a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java index 97672829ec2e..ce426cd35b05 100644 --- a/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java @@ -144,7 +144,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } diff --git a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java index 35a73d36fd10..a4ca5c981ade 100644 --- a/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/GnomeSortTest.java @@ -137,7 +137,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } diff --git a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java index b901e3c542fb..2b423ce9f8ae 100644 --- a/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/InsertionSortTest.java @@ -6,7 +6,6 @@ import java.util.Objects; import java.util.function.Function; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; class InsertionSortTest { @@ -165,7 +164,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } diff --git a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java index a2d3cae15a61..e38bab90c9be 100644 --- a/src/test/java/com/thealgorithms/sorts/SlowSortTest.java +++ b/src/test/java/com/thealgorithms/sorts/SlowSortTest.java @@ -129,7 +129,9 @@ public int compareTo(Person o) { @Override public boolean equals(Object o) { - if (!(o instanceof Person)) return false; + if (!(o instanceof Person)) { + return false; + } Person p = (Person) o; return this.name.equals(p.name) && this.age == p.age; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy