trueskill/tests/Elo/EloAssert.php
2022-07-05 15:33:34 +02:00

43 lines
1.2 KiB
PHP

<?php namespace DNW\Skills\Tests\Elo;
use DNW\Skills\Elo\EloRating;
use DNW\Skills\Elo\FideEloCalculator;
use DNW\Skills\GameInfo;
use DNW\Skills\PairwiseComparison;
use DNW\Skills\Tests\TestCase;
class EloAssert
{
const ERROR_TOLERANCE = 0.1;
public static function assertChessRating(
TestCase $testClass,
FideEloCalculator $twoPlayerEloCalculator,
$player1BeforeRating,
$player2BeforeRating,
$player1Result,
$player1AfterRating,
$player2AfterRating)
{
$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,
$ranks
);
$testClass->assertEquals($player1AfterRating, $result[$player1]->getMean(), '', self::ERROR_TOLERANCE);
$testClass->assertEquals($player2AfterRating, $result[$player2]->getMean(), '', self::ERROR_TOLERANCE);
}
}