|
7 | 7 | public class BucketSortTest {
|
8 | 8 |
|
9 | 9 | @Test
|
10 |
| - public void bucketSortSingleIntegerArray() { |
| 10 | + public void sortSingleIntegerArray() { |
11 | 11 | int[] inputArray = {4};
|
12 |
| - int[] outputArray = BucketSort.bucketSort(inputArray); |
13 | 12 | int[] expectedOutput = {4};
|
14 |
| - assertArrayEquals(outputArray, expectedOutput); |
| 13 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 14 | + assertArrayEquals(expectedOutput, outputArray); |
15 | 15 | }
|
16 | 16 |
|
17 | 17 | @Test
|
18 |
| - public void bucketSortNonDuplicateIntegerArray() { |
19 |
| - int[] inputArray = {6, 1, 99, 27, 15, 23, 36}; |
| 18 | + public void sortEmptyArray() { |
| 19 | + int[] inputArray = {}; |
| 20 | + int[] expectedOutput = {}; |
| 21 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 22 | + assertArrayEquals(expectedOutput, outputArray); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void sortAlreadySortedArray() { |
| 27 | + int[] inputArray = {1, 2, 3, 4, 5, 6, 7}; |
| 28 | + int[] expectedOutput = {1, 2, 3, 4, 5, 6, 7}; |
20 | 29 | int[] outputArray = BucketSort.bucketSort(inputArray);
|
| 30 | + assertArrayEquals(expectedOutput, outputArray); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void sortNonDuplicateIntegerArray() { |
| 35 | + int[] inputArray = {6, 1, 99, 27, 15, 23, 36}; |
21 | 36 | int[] expectedOutput = {1, 6, 15, 23, 27, 36, 99};
|
22 |
| - assertArrayEquals(outputArray, expectedOutput); |
| 37 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 38 | + assertArrayEquals(expectedOutput, outputArray); |
23 | 39 | }
|
24 | 40 |
|
25 | 41 | @Test
|
26 |
| - public void bucketSortDuplicateIntegerArray() { |
| 42 | + public void sortDuplicateIntegerArray() { |
27 | 43 | int[] inputArray = {6, 1, 27, 15, 23, 27, 36, 23};
|
28 |
| - int[] outputArray = BucketSort.bucketSort(inputArray); |
29 | 44 | int[] expectedOutput = {1, 6, 15, 23, 23, 27, 27, 36};
|
30 |
| - assertArrayEquals(outputArray, expectedOutput); |
| 45 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 46 | + assertArrayEquals(expectedOutput, outputArray); |
31 | 47 | }
|
32 | 48 |
|
33 | 49 | @Test
|
34 |
| - public void bucketSortNonDuplicateIntegerArrayWithNegativeNum() { |
| 50 | + public void sortNonDuplicateIntegerArrayWithNegativeNum() { |
35 | 51 | int[] inputArray = {6, -1, 99, 27, -15, 23, -36};
|
36 |
| - int[] outputArray = BucketSort.bucketSort(inputArray); |
37 | 52 | int[] expectedOutput = {-36, -15, -1, 6, 23, 27, 99};
|
38 |
| - assertArrayEquals(outputArray, expectedOutput); |
| 53 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 54 | + assertArrayEquals(expectedOutput, outputArray); |
39 | 55 | }
|
40 | 56 |
|
41 | 57 | @Test
|
42 |
| - public void bucketSortDuplicateIntegerArrayWithNegativeNum() { |
| 58 | + public void sortDuplicateIntegerArrayWithNegativeNum() { |
43 | 59 | int[] inputArray = {6, -1, 27, -15, 23, 27, -36, 23};
|
44 |
| - int[] outputArray = BucketSort.bucketSort(inputArray); |
45 | 60 | int[] expectedOutput = {-36, -15, -1, 6, 23, 23, 27, 27};
|
46 |
| - assertArrayEquals(outputArray, expectedOutput); |
| 61 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 62 | + assertArrayEquals(expectedOutput, outputArray); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void sortLargeArray() { |
| 67 | + int[] inputArray = {100, 50, -100, 200, 0, 150, -50}; |
| 68 | + int[] expectedOutput = {-100, -50, 0, 50, 100, 150, 200}; |
| 69 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 70 | + assertArrayEquals(expectedOutput, outputArray); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void sortArrayWithAllIdenticalElements() { |
| 75 | + int[] inputArray = {5, 5, 5, 5, 5}; |
| 76 | + int[] expectedOutput = {5, 5, 5, 5, 5}; |
| 77 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 78 | + assertArrayEquals(expectedOutput, outputArray); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void sortArrayWithMixedPositiveAndNegativeNumbers() { |
| 83 | + int[] inputArray = {-3, 0, 2, -2, 3, 1, -1}; |
| 84 | + int[] expectedOutput = {-3, -2, -1, 0, 1, 2, 3}; |
| 85 | + int[] outputArray = BucketSort.bucketSort(inputArray); |
| 86 | + assertArrayEquals(expectedOutput, outputArray); |
47 | 87 | }
|
48 | 88 | }
|
0 commit comments