2016-05-24 13:59:35 +02:00
|
|
|
<?php namespace Moserware\Skills\Tests\Elo;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2016-05-24 15:12:29 +02:00
|
|
|
use Moserware\Skills\Elo\EloRating;
|
|
|
|
use Moserware\Skills\Elo\FideEloCalculator;
|
2010-08-28 22:05:41 -04:00
|
|
|
use Moserware\Skills\GameInfo;
|
|
|
|
use Moserware\Skills\PairwiseComparison;
|
2016-05-24 15:12:29 +02:00
|
|
|
use Moserware\Skills\Tests\TestCase;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
|
|
|
class EloAssert
|
|
|
|
{
|
|
|
|
const ERROR_TOLERANCE = 0.1;
|
2016-05-24 13:59:35 +02:00
|
|
|
|
2010-08-28 22:05:41 -04:00
|
|
|
public static function assertChessRating(
|
2016-05-24 15:12:29 +02:00
|
|
|
TestCase $testClass,
|
|
|
|
FideEloCalculator $twoPlayerEloCalculator,
|
2016-05-24 13:59:35 +02:00
|
|
|
$player1BeforeRating,
|
|
|
|
$player2BeforeRating,
|
|
|
|
$player1Result,
|
|
|
|
$player1AfterRating,
|
|
|
|
$player2AfterRating)
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2016-05-24 13:59:35 +02:00
|
|
|
$player1 = "Player1";
|
|
|
|
$player2 = "Player2";
|
|
|
|
|
|
|
|
$teams = array(
|
|
|
|
array($player1 => new EloRating($player1BeforeRating)),
|
|
|
|
array($player2 => new EloRating($player2BeforeRating))
|
|
|
|
);
|
|
|
|
|
|
|
|
$chessGameInfo = new GameInfo(1200, 0, 200);
|
|
|
|
|
|
|
|
$ranks = PairwiseComparison::getRankFromComparison($player1Result);
|
|
|
|
|
|
|
|
$result = $twoPlayerEloCalculator->calculateNewRatings(
|
|
|
|
$chessGameInfo,
|
|
|
|
$teams,
|
2016-05-24 15:12:29 +02:00
|
|
|
$ranks
|
|
|
|
);
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2016-05-24 13:59:35 +02:00
|
|
|
$testClass->assertEquals($player1AfterRating, $result[$player1]->getMean(), '', self::ERROR_TOLERANCE);
|
|
|
|
$testClass->assertEquals($player2AfterRating, $result[$player2]->getMean(), '', self::ERROR_TOLERANCE);
|
|
|
|
}
|
|
|
|
}
|