Skip to content

Commit

Permalink
Add test for draws
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Staa committed Aug 13, 2015
1 parent 8ff1dab commit fb4ac2a
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function setUp()
$this->player2->setRating(1400);
$this->player3->setRating(1550);
$this->player4->setRating(1700);
$this->player5->setRating(1500);

$this->player1->setRatingDeviation(200);
$this->player2->setRatingDeviation(30);
$this->player3->setRatingDeviation(100);
$this->player4->setRatingDeviation(300);

$this->results->addParticipant($this->player5); // the other players will be added to the participants list automatically
$this->player5->setRatingDeviation(350); // default
}

/**
Expand All @@ -50,9 +50,15 @@ public function testGlicko()
$this->assertEquals(0, $this->player1->getGlicko2Rating(), '', 0.00001);
$this->assertEquals(1.1513, $this->player1->getGlicko2RatingDeviation(), '', 0.00001);

$this->results->addResult($this->player1, $this->player2); // player1 beats player 2
$this->results->addResult($this->player3, $this->player1); // player3 beats player 1
$this->results->addResult($this->player4, $this->player1); // player4 beats player 1
// the other players will be added to the participants list automatically
$this->results->addParticipant($this->player5);

// player1 beats player 2
$this->results->addResult($this->player1, $this->player2);
// player3 beats player 1
$this->results->addResult($this->player3, $this->player1);
// player4 beats player 1
$this->results->addResult($this->player4, $this->player1);

$this->ratingSystem->updateRatings($this->results);

Expand All @@ -66,4 +72,20 @@ public function testGlicko()
$this->assertTrue($this->ratingSystem->getDefaultRatingDeviation() < $this->player5->getRatingDeviation(), 'rating deviation should have grown');
$this->assertEquals($this->ratingSystem->getDefaultVolatility(), $this->player5->getVolatility(), 'volatility should be unaffected');
}

/**
* Ensure we handle draws correctly.
*/
public function testDraw()
{
// These players have the same rating, but different RD.
$this->results->addDraw($this->player1, $this->player5);

$this->ratingSystem->updateRatings($this->results);

$this->assertEquals(1500, $this->player1->getRating(), '', 0.01);
$this->assertEquals(1500, $this->player5->getRating(), '', 0.01);
$this->assertLessThan(200, $this->player1->getRatingDeviation(), 'rating deviation should have shrunk');
$this->assertLessThan(350, $this->player5->getRatingDeviation(), 'rating deviation should have shrunk');
}
}

0 comments on commit fb4ac2a

Please sign in to comment.