function randomTest($N, $k) { $es = array(); $a = array(); for ($i = 0; $i < $k; $i++) { $a[$i] = rand(0, $N); } $t1 = microtime(true); $q = new QuickSort($a); $q->sort(); return array('time' => microtime(true) - $t1, 'swaps' => $q->getSwaps(), 'compares' => $q->getCompares()); }
function reorder_data(&$array, $sort_type) { $sort_controller = new QuickSort(SortType::make_sort_type($sort_type)); $sort_controller->sort($array); }
function testQuickFindRandom() { $trials = 100; for ($i = 0; $i < $trials; $i++) { $size = rand(1, 10); $shuffled = QuickSort::shuffle(range(1, 10)); $x = rand(1, $size); $q = new QuickSort($shuffled); $y = $q->find($x); $this->assertEquals($x, $y, "Quick find found incorrect value for {$x} th item in list"); } }
<?php include dirname(__FILE__) . '/../src/autoload.php'; $a = array(20, 10, 50, 90, 30, 70, 60, 40, 80); print_r($a); $q = new QuickSort($a); $a = $q->sort(); print_r($a);