2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-02 14:53:38 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
namespace DNW\Skills\Tests;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
use DNW\Skills\RankSorter;
|
2024-02-01 10:50:18 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2024-05-14 08:46:43 +00:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2016-05-24 14:06:43 +02:00
|
|
|
|
2024-05-14 08:46:43 +00:00
|
|
|
#[CoversClass(RankSorter::class)]
|
2016-05-24 14:06:43 +02:00
|
|
|
class RankSorterTest extends TestCase
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-04 07:03:28 +00:00
|
|
|
public function testSort(): void
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2022-07-05 15:55:47 +02:00
|
|
|
$team1 = ['a' => 1, 'b' => 2];
|
|
|
|
$team2 = ['c' => 3, 'd' => 4];
|
|
|
|
$team3 = ['e' => 5, 'f' => 6];
|
2016-05-24 15:12:29 +02:00
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
$teams = [$team1, $team2, $team3];
|
2016-05-24 15:12:29 +02:00
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
$teamRanks = [3, 1, 2];
|
2016-05-24 15:12:29 +02:00
|
|
|
|
2010-08-28 22:05:41 -04:00
|
|
|
$sortedRanks = RankSorter::sort($teams, $teamRanks);
|
2016-05-24 15:12:29 +02:00
|
|
|
|
|
|
|
$this->assertEquals($team2, $sortedRanks[0]);
|
2010-08-28 22:05:41 -04:00
|
|
|
$this->assertEquals($team3, $sortedRanks[1]);
|
|
|
|
$this->assertEquals($team1, $sortedRanks[2]);
|
2016-05-24 15:58:39 +02:00
|
|
|
|
|
|
|
// Since we are also using a return
|
|
|
|
$this->assertEquals($team2, $teams[0]);
|
|
|
|
$this->assertEquals($team3, $teams[1]);
|
|
|
|
$this->assertEquals($team1, $teams[2]);
|
|
|
|
|
|
|
|
// Since we're passing a reference, but also get a return
|
|
|
|
$this->assertEquals($teams[0], $sortedRanks[0]);
|
|
|
|
$this->assertEquals($teams[1], $sortedRanks[1]);
|
|
|
|
$this->assertEquals($teams[2], $sortedRanks[2]);
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|