|
| 1 | +package com.thealgorithms.sorts; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +/** |
| 8 | + * @author Akshay Dubey (https://github.com/itsAkshayDubey) |
| 9 | + * @see QuickSort |
| 10 | + */ |
| 11 | +class QuickSortTest { |
| 12 | + |
| 13 | + private QuickSort quickSort = new QuickSort(); |
| 14 | + |
| 15 | + @Test |
| 16 | + void quickSortEmptyArrayShouldPass() |
| 17 | + { |
| 18 | + Integer[] array = {}; |
| 19 | + Integer[] sorted = quickSort.sort(array); |
| 20 | + Integer[] expected = {}; |
| 21 | + assertArrayEquals(expected, sorted); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void quickSortSingleValueArrayShouldPass() |
| 26 | + { |
| 27 | + Integer[] array = {7}; |
| 28 | + Integer[] sorted = quickSort.sort(array); |
| 29 | + Integer[] expected = {7}; |
| 30 | + assertArrayEquals(expected, sorted); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void quickSortWithIntegerArrayShouldPass() |
| 35 | + { |
| 36 | + Integer[] array = {49,4,36,9,144,1}; |
| 37 | + Integer[] sorted = quickSort.sort(array); |
| 38 | + Integer[] expected = {1,4,9,36,49,144}; |
| 39 | + assertArrayEquals(expected, sorted); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void quickSortForArrayWithNegativeValuesShouldPass() |
| 44 | + { |
| 45 | + Integer[] array = {49,-36,-144,-49,1,9}; |
| 46 | + Integer[] sorted = quickSort.sort(array); |
| 47 | + Integer[] expected = {-144,-49,-36,1,9,49}; |
| 48 | + assertArrayEquals(expected, sorted); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + void quickSortForArrayWithDuplicateValuesShouldPass() |
| 53 | + { |
| 54 | + Integer[] array = {36,1,49,1,4,9}; |
| 55 | + Integer[] sorted = quickSort.sort(array); |
| 56 | + Integer[] expected = {1,1,4,9,36,49}; |
| 57 | + assertArrayEquals(expected, sorted); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void quickSortWithStringArrayShouldPass() |
| 62 | + { |
| 63 | + String[] array = {"c", "a", "e", "b", "d"}; |
| 64 | + String[] sorted = quickSort.sort(array); |
| 65 | + String[] expected = {"a","b","c","d","e"}; |
| 66 | + assertArrayEquals(expected, sorted); |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments