|
6 | 6 | require_once __DIR__ . '/../../Sorting/BubbleSort.php';
|
7 | 7 | require_once __DIR__ . '/../../Sorting/BubbleSort2.php';
|
8 | 8 | require_once __DIR__ . '/../../Sorting/CountSort.php';
|
| 9 | +require_once __DIR__ . '/../../Sorting/HeapSort.php'; |
9 | 10 | require_once __DIR__ . '/../../Sorting/InsertionSort.php';
|
10 | 11 | require_once __DIR__ . '/../../Sorting/MergeSort.php';
|
11 | 12 | require_once __DIR__ . '/../../Sorting/QuickSort.php';
|
@@ -172,4 +173,29 @@ public function testQuickSortCipher()
|
172 | 173 | $this->assertEquals($result1, $test1);
|
173 | 174 | $this->assertEquals($result2, $test2);
|
174 | 175 | }
|
| 176 | + |
| 177 | + public function testHeapSortPerformance() |
| 178 | + { |
| 179 | + $array = range(1, 1000000); |
| 180 | + shuffle($array); // Randomize the order |
| 181 | + $start = microtime(true); |
| 182 | + heapSort($array); |
| 183 | + $end = microtime(true); |
| 184 | + $this->assertLessThan(1, $end - $start); |
| 185 | + } |
| 186 | + |
| 187 | + public function testHeapSortCipher() |
| 188 | + { |
| 189 | + $firstArray = [20, 16, -5, -8, 6, 12, 2, 4, -3, 9]; |
| 190 | + $expectedResultOne = [-8, -5, -3, 2, 4, 6, 9, 12, 16, 20]; |
| 191 | + |
| 192 | + $secondArray = [-6, 12, 14, 17, 5, 4, -9, 15, 0, -8]; |
| 193 | + $expectedResultTwo = [-9, -8, -6, 0, 4, 5, 12, 14, 15, 17]; |
| 194 | + |
| 195 | + $resultOne = heapSort($firstArray); |
| 196 | + $resultTwo = heapSort($secondArray); |
| 197 | + |
| 198 | + $this->assertEquals($expectedResultOne, $resultOne); |
| 199 | + $this->assertEquals($expectedResultTwo, $resultTwo); |
| 200 | + } |
175 | 201 | }
|
0 commit comments