2727use doganoo \PHPAlgorithms \Algorithm \Sorting \BubbleSort ;
2828use doganoo \PHPAlgorithms \Algorithm \Sorting \InsertionSort ;
2929use doganoo \PHPAlgorithms \Algorithm \Sorting \MergeSort ;
30+ use doganoo \PHPAlgorithms \Algorithm \Sorting \QuickSort ;
3031use doganoo \PHPAlgorithms \Algorithm \Sorting \SelectionSort ;
32+ use doganoo \PHPAlgorithms \Algorithm \Sorting \TimSort ;
3133
3234/**
3335 * Class SortTest
@@ -37,24 +39,95 @@ public function testBubbleSort() {
3739 $ bubbleSort = new BubbleSort ();
3840 $ result = $ bubbleSort ->sort ([12 , 40 , 9 , 55 , 1 , 13 ]);
3941 $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
42+
43+ $ result = $ bubbleSort ->sort ([]);
44+ $ this ->assertTrue ($ result === []);
45+
46+ $ result = $ bubbleSort ->sort ([9 ]);
47+ $ this ->assertTrue ($ result === [9 ]);
4048 }
4149
4250 public function testSelectionSort () {
43- $ bubbleSort = new SelectionSort ();
44- $ result = $ bubbleSort ->sort ([12 , 40 , 9 , 55 , 1 , 13 ]);
51+ $ selectionSort = new SelectionSort ();
52+ $ result = $ selectionSort ->sort ([12 , 40 , 9 , 55 , 1 , 13 ]);
4553 $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
54+
55+ $ result = $ selectionSort ->sort ([]);
56+ $ this ->assertTrue ($ result === []);
57+
58+ $ result = $ selectionSort ->sort ([9 ]);
59+ $ this ->assertTrue ($ result === [9 ]);
4660 }
4761
4862 public function testMergeSort () {
49- $ bubbleSort = new MergeSort ();
63+ $ mergeSort = new MergeSort ();
5064 $ arr = [12 , 40 , 9 , 55 , 1 , 13 ];
51- $ result = $ bubbleSort ->sort ($ arr );
65+ $ result = $ mergeSort ->sort ($ arr );
5266 $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
67+
68+ $ result = $ mergeSort ->sort ([]);
69+ $ this ->assertTrue ($ result === []);
70+
71+ $ result = $ mergeSort ->sort ([9 ]);
72+ $ this ->assertTrue ($ result === [9 ]);
5373 }
74+
5475 public function testInsertionSort () {
55- $ bubbleSort = new InsertionSort ();
76+ $ insertionSort = new InsertionSort ();
77+ $ arr = [12 , 40 , 9 , 55 , 1 , 13 ];
78+ $ result = $ insertionSort ->sort ($ arr );
79+ $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
80+
81+ $ result = $ insertionSort ->sort ([]);
82+ $ this ->assertTrue ($ result === []);
83+
84+ $ result = $ insertionSort ->sort ([9 ]);
85+ $ this ->assertTrue ($ result === [9 ]);
86+ }
87+
88+ public function testTimSort () {
89+ $ timSort = new TimSort ();
5690 $ arr = [12 , 40 , 9 , 55 , 1 , 13 ];
57- $ result = $ bubbleSort ->sort ($ arr );
91+ $ result = $ timSort ->sort ($ arr );
5892 $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
93+
94+ $ arr = [5 , 21 , 7 , 23 , 19 ];
95+ $ result = $ timSort ->sort ($ arr );
96+ $ this ->assertTrue ($ result === [5 , 7 , 19 , 21 , 23 ]);
97+
98+ $ arr = [2 , 3 , 1 , 5 , 6 , 7 ];
99+ $ result = $ timSort ->sort ($ arr );
100+ $ this ->assertTrue ($ result === [1 , 2 , 3 , 5 , 6 , 7 ]);
101+
102+ $ arr = [];
103+ $ result = $ timSort ->sort ($ arr );
104+ $ this ->assertTrue ($ result === []);
105+
106+ $ arr = [1 ];
107+ $ result = $ timSort ->sort ($ arr );
108+ $ this ->assertTrue ($ result === [1 ]);
109+ }
110+
111+ public function testQuickSort () {
112+ $ quickSort = new QuickSort ();
113+ $ arr = [12 , 40 , 9 , 55 , 1 , 13 ];
114+ $ result = $ quickSort ->sort ($ arr );
115+ $ this ->assertTrue ($ result === [1 , 9 , 12 , 13 , 40 , 55 ]);
116+
117+ $ arr = [5 , 21 , 7 , 23 , 19 ];
118+ $ result = $ quickSort ->sort ($ arr );
119+ $ this ->assertTrue ($ result === [5 , 7 , 19 , 21 , 23 ]);
120+
121+ $ arr = [2 , 3 , 1 , 5 , 6 , 7 ];
122+ $ result = $ quickSort ->sort ($ arr );
123+ $ this ->assertTrue ($ result === [1 , 2 , 3 , 5 , 6 , 7 ]);
124+
125+ $ arr = [];
126+ $ result = $ quickSort ->sort ($ arr );
127+ $ this ->assertTrue ($ result === []);
128+
129+ $ arr = [1 ];
130+ $ result = $ quickSort ->sort ($ arr );
131+ $ this ->assertTrue ($ result === [1 ]);
59132 }
60133}
0 commit comments