Skip to content

Add quick sort tests #3165

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

Merged
merged 4 commits into from
Jun 24, 2022
Merged
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
Add unit tests to QuickSortTest.java
  • Loading branch information
itsAkshayDubey committed Jun 23, 2022
commit 8dff1ef0ae312f0e07cf6e45ee6548141e8dbfe6
64 changes: 64 additions & 0 deletions src/test/java/com/thealgorithms/sorts/QuickSortTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
package com.thealgorithms.sorts;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import org.junit.jupiter.api.Test;

/**
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
* @see QuickSort
*/
class QuickSortTest {

private QuickSort quickSort = new QuickSort();

@Test
void quickSortEmptyArrayShouldPass()
{
Integer[] array = {};
Integer[] sorted = quickSort.sort(array);
Integer[] expected = {};
assertArrayEquals(expected, sorted);
}

@Test
void quickSortSingleValueArrayShouldPass()
{
Integer[] array = {7};
Integer[] sorted = quickSort.sort(array);
Integer[] expected = {7};
assertArrayEquals(expected, sorted);
}

@Test
void quickSortWithIntegerArrayShouldPass()
{
Integer[] array = {49,4,36,9,144,1};
Integer[] sorted = quickSort.sort(array);
Integer[] expected = {1,4,9,36,49,144};
assertArrayEquals(expected, sorted);
}

@Test
void quickSortForArrayWithNegativeValuesShouldPass()
{
Integer[] array = {49,-36,-144,-49,1,9};
Integer[] sorted = quickSort.sort(array);
Integer[] expected = {-144,-49,-36,1,9,49};
assertArrayEquals(expected, sorted);
}

@Test
void quickSortForArrayWithDuplicateValuesShouldPass()
{
Integer[] array = {36,1,49,1,4,9};
Integer[] sorted = quickSort.sort(array);
Integer[] expected = {1,1,4,9,36,49};
assertArrayEquals(expected, sorted);
}

@Test
void quickSortWithStringArrayShouldPass()
{
String[] array = {"c", "a", "e", "b", "d"};
String[] sorted = quickSort.sort(array);
String[] expected = {"a","b","c","d","e"};
assertArrayEquals(expected, sorted);
}

}