Skip to content

Added test cases for sorting algorithms #6345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatted the newly added tests using clang-format
  • Loading branch information
pushkar committed Jul 6, 2025
commit 853d2e46f0ec334220fb2e94a08473ec5b181715
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/com/thealgorithms/sorts/BogoSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions src/test/java/com/thealgorithms/sorts/BubbleSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

}
15 changes: 7 additions & 8 deletions src/test/java/com/thealgorithms/sorts/GnomeSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/thealgorithms/sorts/InsertionSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/com/thealgorithms/sorts/SlowSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Loading
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