mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.4
|
|
*
|
|
* @package tests
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link https://orange-management.org
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\tests\Algorithm\Sort;
|
|
|
|
use phpOMS\Algorithm\Sort\BucketSort;
|
|
use phpOMS\Algorithm\Sort\SortOrder;
|
|
|
|
require_once __DIR__ . '/../../Autoloader.php';
|
|
|
|
/**
|
|
* @testdox phpOMS\tests\Algorithm\Sort: Bucket sort test
|
|
*
|
|
* @internal
|
|
*/
|
|
class BucketSortTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
protected $list = [];
|
|
|
|
protected function setUp() : void
|
|
{
|
|
$this->list = [
|
|
new NumericElement(5),
|
|
new NumericElement(1),
|
|
new NumericElement(4),
|
|
new NumericElement(2),
|
|
new NumericElement(8),
|
|
];
|
|
}
|
|
|
|
public function testSortASC() : void
|
|
{
|
|
$newList = BucketSort::sort($this->list, 2, \phpOMS\Algorithm\Sort\SelectionSort::class);
|
|
self::assertEquals(
|
|
[1, 2, 4, 5, 8], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
|
);
|
|
}
|
|
|
|
public function testSortDESC() : void
|
|
{
|
|
$newList = BucketSort::sort($this->list, 2, \phpOMS\Algorithm\Sort\SelectionSort::class, SortOrder::DESC);
|
|
self::assertEquals(
|
|
[8, 5, 4, 2, 1], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
|
);
|
|
}
|
|
}
|