mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
Tests passing
This commit is contained in:
@ -53,12 +53,19 @@ abstract class SkillCalculator
|
||||
self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->_totalTeamsAllowed, $this->_playersPerTeamAllowed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<\DNW\Skills\Team> $teams
|
||||
* @param \DNW\Skills\TeamsRange $totalTeams
|
||||
* @param \DNW\Skills\PlayersRange $playersPerTeam
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam)
|
||||
{
|
||||
$countOfTeams = 0;
|
||||
|
||||
foreach ($teams as $currentTeam) {
|
||||
if (! $playersPerTeam->isInRange(count($currentTeam))) {
|
||||
if (! $playersPerTeam->isInRange($currentTeam->count())) {
|
||||
throw new Exception('Player count is not in range');
|
||||
}
|
||||
$countOfTeams++;
|
||||
|
@ -8,6 +8,7 @@ use DNW\Skills\Rating;
|
||||
use DNW\Skills\SkillCalculator;
|
||||
use DNW\Skills\Team;
|
||||
use DNW\Skills\Teams;
|
||||
use DNW\Skills\Tests\TestCase;
|
||||
|
||||
class TrueSkillCalculatorTests
|
||||
{
|
||||
@ -17,7 +18,7 @@ class TrueSkillCalculatorTests
|
||||
|
||||
// These are the roll-up ones
|
||||
|
||||
public static function testAllTwoPlayerScenarios($testClass, SkillCalculator $calculator)
|
||||
public static function testAllTwoPlayerScenarios(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
self::twoPlayerTestNotDrawn($testClass, $calculator);
|
||||
self::twoPlayerTestDrawn($testClass, $calculator);
|
||||
@ -25,7 +26,7 @@ class TrueSkillCalculatorTests
|
||||
self::oneOnOneMassiveUpsetDrawTest($testClass, $calculator);
|
||||
}
|
||||
|
||||
public static function testAllTwoTeamScenarios($testClass, SkillCalculator $calculator)
|
||||
public static function testAllTwoTeamScenarios(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
self::oneOnTwoSimpleTest($testClass, $calculator);
|
||||
self::oneOnTwoSomewhatBalanced($testClass, $calculator);
|
||||
@ -44,7 +45,7 @@ class TrueSkillCalculatorTests
|
||||
self::fourOnFourSimpleTest($testClass, $calculator);
|
||||
}
|
||||
|
||||
public static function testAllMultipleTeamScenarios($testClass, SkillCalculator $calculator)
|
||||
public static function testAllMultipleTeamScenarios(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
self::threeTeamsOfOneNotDrawn($testClass, $calculator);
|
||||
self::threeTeamsOfOneDrawn($testClass, $calculator);
|
||||
@ -56,7 +57,7 @@ class TrueSkillCalculatorTests
|
||||
self::twoOnFourOnTwoWinDraw($testClass, $calculator);
|
||||
}
|
||||
|
||||
public static function testPartialPlayScenarios($testClass, SkillCalculator $calculator)
|
||||
public static function testPartialPlayScenarios(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
self::oneOnTwoBalancedPartialPlay($testClass, $calculator);
|
||||
}
|
||||
@ -75,7 +76,7 @@ class TrueSkillCalculatorTests
|
||||
// Two Player Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
private static function twoPlayerTestNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function twoPlayerTestNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -96,7 +97,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function twoPlayerTestDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function twoPlayerTestDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -118,7 +119,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function twoPlayerChessTestNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function twoPlayerChessTestNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
// Inspired by a real bug :-)
|
||||
$player1 = new Player(1);
|
||||
@ -137,7 +138,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertRating($testClass, 1185.0383099003536, 42.485604606897752, $player2NewRating);
|
||||
}
|
||||
|
||||
private static function oneOnOneMassiveUpsetDrawTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnOneMassiveUpsetDrawTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -166,7 +167,7 @@ class TrueSkillCalculatorTests
|
||||
// Two Team Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
private static function oneOnTwoSimpleTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnTwoSimpleTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -199,7 +200,7 @@ class TrueSkillCalculatorTests
|
||||
// Two Team Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
private static function twoOnTwoSimpleTest($testClass, SkillCalculator $calculator)
|
||||
private static function twoOnTwoSimpleTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -231,7 +232,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function oneOnTwoSomewhatBalanced($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnTwoSomewhatBalanced(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -260,7 +261,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.478, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function oneOnThreeSimpleTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnThreeSimpleTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -292,7 +293,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.012, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function oneOnTwoDrawTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnTwoDrawTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -321,7 +322,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.135, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function oneOnThreeDrawTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnThreeDrawTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -353,7 +354,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.012, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function oneOnSevenSimpleTest($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnSevenSimpleTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
|
||||
@ -397,7 +398,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.000, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function threeOnTwoTests($testClass, SkillCalculator $calculator)
|
||||
private static function threeOnTwoTests(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -443,7 +444,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.254, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function twoOnTwoUnbalancedDrawTest($testClass, SkillCalculator $calculator)
|
||||
private static function twoOnTwoUnbalancedDrawTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -475,7 +476,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.214, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function twoOnTwoUpsetTest($testClass, SkillCalculator $calculator)
|
||||
private static function twoOnTwoUpsetTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -507,7 +508,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.084, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function fourOnFourSimpleTest($testClass, SkillCalculator $calculator)
|
||||
private static function fourOnFourSimpleTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -552,7 +553,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function twoOnTwoDrawTest($testClass, SkillCalculator $calculator)
|
||||
private static function twoOnTwoDrawTest(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -584,7 +585,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.447, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function threeTeamsOfOneNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function threeTeamsOfOneNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -611,7 +612,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.200, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function threeTeamsOfOneDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function threeTeamsOfOneDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -638,7 +639,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.200, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function fourTeamsOfOneNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function fourTeamsOfOneNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -670,7 +671,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.089, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function fiveTeamsOfOneNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function fiveTeamsOfOneNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -706,7 +707,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.040, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function eightTeamsOfOneDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function eightTeamsOfOneDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -757,7 +758,7 @@ class TrueSkillCalculatorTests
|
||||
self::AssertMatchQuality($testClass, 0.004, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function eightTeamsOfOneUpset($testClass, SkillCalculator $calculator)
|
||||
private static function eightTeamsOfOneUpset(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -809,7 +810,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.000, $calculator->calculateMatchQuality($gameInfo, $teams));
|
||||
}
|
||||
|
||||
private static function sixteenTeamsOfOneNotDrawn($testClass, SkillCalculator $calculator)
|
||||
private static function sixteenTeamsOfOneNotDrawn(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -906,7 +907,7 @@ class TrueSkillCalculatorTests
|
||||
self::assertRating($testClass, 9.46054223053080, 5.27581643889032, $player16NewRating);
|
||||
}
|
||||
|
||||
private static function twoOnFourOnTwoWinDraw($testClass, SkillCalculator $calculator)
|
||||
private static function twoOnFourOnTwoWinDraw(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$player1 = new Player(1);
|
||||
$player2 = new Player(2);
|
||||
@ -955,7 +956,7 @@ class TrueSkillCalculatorTests
|
||||
// Partial Play Tests
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
private static function oneOnTwoBalancedPartialPlay($testClass, SkillCalculator $calculator)
|
||||
private static function oneOnTwoBalancedPartialPlay(TestCase $testClass, SkillCalculator $calculator)
|
||||
{
|
||||
$gameInfo = new GameInfo();
|
||||
|
||||
@ -985,14 +986,14 @@ class TrueSkillCalculatorTests
|
||||
self::assertMatchQuality($testClass, 0.44721358745011336, $matchQuality);
|
||||
}
|
||||
|
||||
private static function assertRating($testClass, $expectedMean, $expectedStandardDeviation, $actual)
|
||||
private static function assertRating(TestCase $testClass, $expectedMean, $expectedStandardDeviation, $actual)
|
||||
{
|
||||
$testClass->assertEquals($expectedMean, $actual->getMean(), '', self::ERROR_TOLERANCE_TRUESKILL);
|
||||
$testClass->assertEquals($expectedStandardDeviation, $actual->getStandardDeviation(), '', self::ERROR_TOLERANCE_TRUESKILL);
|
||||
$testClass->assertEqualsWithDelta($expectedMean, $actual->getMean(), self::ERROR_TOLERANCE_TRUESKILL);
|
||||
$testClass->assertEqualsWithDelta($expectedStandardDeviation, $actual->getStandardDeviation(),self::ERROR_TOLERANCE_TRUESKILL);
|
||||
}
|
||||
|
||||
private static function assertMatchQuality($testClass, $expectedMatchQuality, $actualMatchQuality)
|
||||
private static function assertMatchQuality(TestCase $testClass, $expectedMatchQuality, $actualMatchQuality)
|
||||
{
|
||||
$testClass->assertEquals($expectedMatchQuality, $actualMatchQuality, '', self::ERROR_TOLERANCE_MATCH_QUALITY);
|
||||
$testClass->assertEqualsWithDelta($expectedMatchQuality, $actualMatchQuality, self::ERROR_TOLERANCE_MATCH_QUALITY);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user