1+ package com .thealgorithms .sorts ;
2+
3+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
4+
5+ import org .junit .jupiter .api .DisplayName ;
6+ import org .junit .jupiter .api .Test ;
7+
8+ /**
9+ * Unit tests for the SmoothSort class.
10+ */
11+ final class SmoothSortTest {
12+
13+ @ Test
14+ @ DisplayName ("Test with an empty array" )
15+ void testSortEmptyArray () {
16+ Integer [] array = {};
17+ SmoothSort .sort (array );
18+ assertArrayEquals (new Integer [] {}, array );
19+ }
20+
21+ @ Test
22+ @ DisplayName ("Test with a single-element array" )
23+ void testSortSingleElementArray () {
24+ Integer [] array = {42 };
25+ SmoothSort .sort (array );
26+ assertArrayEquals (new Integer [] {42 }, array );
27+ }
28+
29+ @ Test
30+ @ DisplayName ("Test with a simple unsorted array of integers" )
31+ void testSortSimpleIntegerArray () {
32+ Integer [] array = {5 , 8 , 3 , 1 , 9 , 4 , 7 , 2 , 6 };
33+ Integer [] expected = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
34+ SmoothSort .sort (array );
35+ assertArrayEquals (expected , array );
36+ }
37+
38+ @ Test
39+ @ DisplayName ("Test with an already sorted array (best case)" )
40+ void testSortAlreadySortedArray () {
41+ Integer [] array = {10 , 20 , 30 , 40 , 50 };
42+ Integer [] expected = {10 , 20 , 30 , 40 , 50 };
43+ SmoothSort .sort (array );
44+ assertArrayEquals (expected , array );
45+ }
46+
47+ @ Test
48+ @ DisplayName ("Test with a reverse sorted array (worst case)" )
49+ void testSortReverseSortedArray () {
50+ Integer [] array = {55 , 44 , 33 , 22 , 11 };
51+ Integer [] expected = {11 , 22 , 33 , 44 , 55 };
52+ SmoothSort .sort (array );
53+ assertArrayEquals (expected , array );
54+ }
55+
56+ @ Test
57+ @ DisplayName ("Test with an array containing duplicate elements" )
58+ void testSortArrayWithDuplicates () {
59+ Integer [] array = {7 , 2 , 9 , 2 , 5 , 7 , 9 , 1 , 5 };
60+ Integer [] expected = {1 , 2 , 2 , 5 , 5 , 7 , 7 , 9 , 9 };
61+ SmoothSort .sort (array );
62+ assertArrayEquals (expected , array );
63+ }
64+
65+ @ Test
66+ @ DisplayName ("Test with an array of strings" )
67+ void testSortStringArray () {
68+ String [] array = {"banana" , "apple" , "cherry" , "date" , "fig" };
69+ String [] expected = {"apple" , "banana" , "cherry" , "date" , "fig" };
70+ SmoothSort .sort (array );
71+ assertArrayEquals (expected , array );
72+ }
73+
74+ @ Test
75+ @ DisplayName ("Test with an array containing negative numbers" )
76+ void testSortArrayWithNegativeNumbers () {
77+ Integer [] array = {-5 , 8 , -3 , 0 , 9 , -4 , 7 , 2 , -6 };
78+ Integer [] expected = {-6 , -5 , -4 , -3 , 0 , 2 , 7 , 8 , 9 };
79+ SmoothSort .sort (array );
80+ assertArrayEquals (expected , array );
81+ }
82+ }
0 commit comments