Closed
Description
We saw that there was no test writing for the Quicksort Algorithm and We decided to write some test for the quicksort algorithm.Below is the code that we wrote for it.
`package com.thealgorithms.sorts;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
- @author Hambalieu Jallow (https://github.com/Hambalieu)
- @author Tony Regalado (https://github.com/Edward-Regalado)
*/
class QuickSortTest {
@Test
@DisplayName("Empty Array")
void quickSortEmptyArray()
{
QuickSort sut = new QuickSort();
Integer[] array = {};
Integer[] sorted = sut.sort(array);
Integer[] expected = {};
assertArrayEquals(expected, sorted);
}
@Test
@DisplayName("Array has a single Value")
void quickSortSingleValueArray()
{
QuickSort sut = new QuickSort();
Integer[] array = {4};
Integer[] sorted = sut.sort(array);
Integer[] expected = {4};
assertArrayEquals(expected, sorted);
}
@Test
@DisplayName("merge sort array of integers")
void quickSort()
{
QuickSort sut = new QuickSort();
Integer[] array = {8, 4, 23, 42, 16, 15};
Integer[] sorted = sut.sort(array);
Integer[] expected = {4, 8, 15, 16, 23, 42};
assertArrayEquals(expected, sorted);
}
@Test
@DisplayName("sort array with negative values")
void quickSortNegativeValue()
{
QuickSort sut = new QuickSort();
Integer[] array = {8, -4, 23, -42, 16, 15};
Integer[] sorted = sut.sort(array);
Integer[] expected = {-42, -4, 8, 15, 16, 23};
assertArrayEquals(expected, sorted);
}
@Test
@DisplayName("array has duplicate values")
void quickSortDuplicateValues()
{
QuickSort sut = new QuickSort();
Integer[] array = {8, 4, 23, 42, 4, 15};
Integer[] sorted = sut.sort(array);
Integer[] expected = {4, 4, 8, 15, 23, 42};
assertArrayEquals(expected, sorted);
}
}
`
Metadata
Metadata
Assignees
Labels
No labels