mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
More tests
This commit is contained in:
@ -11,13 +11,6 @@ class Teams
|
||||
*/
|
||||
public static function concat(Team ...$args/*variable arguments*/): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($args as $currentTeam) {
|
||||
$localCurrentTeam = $currentTeam;
|
||||
$result[] = $localCurrentTeam;
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace DNW\Skills\Tests;
|
||||
|
||||
use DNW\Skills\GameInfo;
|
||||
use \DNW\Skills\Rating;
|
||||
use DNW\Skills\Rating;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
@ -10,7 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
|
||||
#[CoversClass(Player::class)]
|
||||
#[UsesClass(Guard::class)]
|
||||
class PlayerTest extends TestCase
|
||||
|
47
tests/RatingContainerTest.php
Normal file
47
tests/RatingContainerTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DNW\Skills\Tests;
|
||||
|
||||
use DNW\Skills\RatingContainer;
|
||||
use DNW\Skills\HashMap;
|
||||
use DNW\Skills\Player;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\Guard;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
#[CoversClass(RatingContainer::class)]
|
||||
#[UsesClass(Hashmap::class)]
|
||||
#[UsesClass(Player::class)]
|
||||
#[UsesClass(Rating::class)]
|
||||
#[UsesClass(Guard::class)]
|
||||
class RatingContainerTest extends TestCase
|
||||
{
|
||||
public function testRatingContainer(): void
|
||||
{
|
||||
$rc = new RatingContainer();
|
||||
|
||||
$this->assertEquals([], $rc->getAllPlayers());
|
||||
$this->assertEquals([], $rc->getAllRatings());
|
||||
$this->assertEquals(0, $rc->count());
|
||||
|
||||
$p1 = new Player(1);
|
||||
$p2 = new Player(2);
|
||||
|
||||
$r1 = new Rating(100, 10);
|
||||
$r2 = new Rating(200, 20);
|
||||
|
||||
$rc->setRating($p1, $r1);
|
||||
$rc->setRating($p2, $r2);
|
||||
|
||||
$this->assertEquals($r1, $rc->getRating($p1));
|
||||
$this->assertEquals($r2, $rc->getRating($p2));
|
||||
|
||||
$this->assertEquals([$p1, $p2], $rc->getAllPlayers());
|
||||
$this->assertEquals([$r1, $r2], $rc->getAllRatings());
|
||||
$this->assertEquals(2, $rc->count());
|
||||
}
|
||||
}
|
69
tests/TeamTest.php
Normal file
69
tests/TeamTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DNW\Skills\Tests;
|
||||
|
||||
use DNW\Skills\Team;
|
||||
use DNW\Skills\RatingContainer;
|
||||
use DNW\Skills\HashMap;
|
||||
use DNW\Skills\Player;
|
||||
use DNW\Skills\Rating;
|
||||
use DNW\Skills\Guard;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
#[CoversClass(Team::class)]
|
||||
#[CoversClass(RatingContainer::class)]
|
||||
#[UsesClass(Hashmap::class)]
|
||||
#[UsesClass(Player::class)]
|
||||
#[UsesClass(Rating::class)]
|
||||
#[UsesClass(Guard::class)]
|
||||
class TeamTest extends TestCase
|
||||
{
|
||||
public function testTeam(): void
|
||||
{
|
||||
$p1 = new Player(1);
|
||||
$p2 = new Player(2);
|
||||
|
||||
$r1 = new Rating(100, 10);
|
||||
$r2 = new Rating(200, 20);
|
||||
|
||||
$rc = new Team($p1, $r1);
|
||||
|
||||
$this->assertEquals($r1, $rc->getRating($p1));
|
||||
$this->assertEquals([$p1], $rc->getAllPlayers());
|
||||
$this->assertEquals([$r1], $rc->getAllRatings());
|
||||
$this->assertEquals(1, $rc->count());
|
||||
|
||||
$rc->addPlayer($p2, $r2);
|
||||
|
||||
$this->assertEquals($r2, $rc->getRating($p2));
|
||||
|
||||
$this->assertEquals([$p1, $p2], $rc->getAllPlayers());
|
||||
$this->assertEquals([$r1, $r2], $rc->getAllRatings());
|
||||
$this->assertEquals(2, $rc->count());
|
||||
}
|
||||
|
||||
public function testTeamConstructor(): void
|
||||
{
|
||||
$p = new Player(0);
|
||||
$r = new Rating(100, 10);
|
||||
|
||||
$rc = new Team(NULL, NULL);
|
||||
$this->assertEquals(0, $rc->count());
|
||||
|
||||
$rc = new Team($p, NULL);
|
||||
$this->assertEquals(0, $rc->count());
|
||||
|
||||
$rc = new Team(NULL, $r);
|
||||
$this->assertEquals(0, $rc->count());
|
||||
|
||||
$rc = new Team($p, $r);
|
||||
$this->assertEquals($r, $rc->getRating($p));
|
||||
$this->assertEquals([$p], $rc->getAllPlayers());
|
||||
$this->assertEquals([$r], $rc->getAllRatings());
|
||||
$this->assertEquals(1, $rc->count());
|
||||
}
|
||||
}
|
28
tests/TeamsTest.php
Normal file
28
tests/TeamsTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DNW\Skills\Tests;
|
||||
|
||||
use DNW\Skills\Teams;
|
||||
use DNW\Skills\Team;
|
||||
use DNW\Skills\RatingContainer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
#[CoversClass(Teams::class)]
|
||||
#[UsesClass(Team::class)]
|
||||
#[UsesClass(RatingContainer::class)]
|
||||
class TeamsTest extends TestCase
|
||||
{
|
||||
public function testTeamsConcat(): void
|
||||
{
|
||||
$t1 = new Team();
|
||||
$t2 = new Team();
|
||||
$t3 = new Team();
|
||||
|
||||
$this->assertEquals([$t1], Teams::concat($t1));
|
||||
$this->assertEquals([$t1, $t2, $t3], Teams::concat($t1, $t2, $t3));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user