Skip to content

Commit

Permalink
Another part of the partial fix. Needs more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Jan 19, 2018
1 parent ac67523 commit bb8a983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 4 additions & 0 deletions models/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ public function invalidateMatchFromCache(Match $match)
$seasonKey = $this->buildSeasonKeyFromTimestamp($match->getTimestamp());
$seasonElo = null;

if (!isset($this->eloSeasonHistory[$seasonKey][$match->getId()])) {
return;
}

$eloChangelogIndex = array_search($match->getId(), array_keys($this->eloSeasonHistory[$seasonKey]));
$slicedChangeLog = array_slice($this->eloSeasonHistory[$seasonKey], 0, $eloChangelogIndex, true);

Expand Down
13 changes: 2 additions & 11 deletions tests/ModelTests/MatchEloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function testEloRecalculation()

$matchToEdit = $matches[3];

$matchResult = $matchToEdit->getMatchDescription($team);
$scoreTeamA = $matchToEdit->getScore($matchToEdit->getTeamA());
$scoreTeamB = $matchToEdit->getScore($matchToEdit->getTeamB());

Expand All @@ -78,16 +77,8 @@ public function testEloRecalculation()
$newLeaderElo = Player::get($team->getLeader())->getElo();
$newTeamElo = Team::get($team->getId())->getElo();

if ($matchResult === 'win') {
$this->assertLessThan($preRecalcLeaderElo, $newLeaderElo);
$this->assertLessThan($preRecalcTeamElo, $newTeamElo);
} elseif ($matchResult === 'loss') {
$this->assertGreaterThan($preRecalcLeaderElo, $newLeaderElo);
$this->assertGreaterThan($preRecalcTeamElo, $newTeamElo);
} else {
$this->assertEquals($preRecalcLeaderElo, $newLeaderElo);
$this->assertEquals($preRecalcTeamElo, $newTeamElo);
}
$this->assertNotEquals($preRecalcLeaderElo, $newLeaderElo);
$this->assertNotEquals($preRecalcTeamElo, $newTeamElo);
}

/**
Expand Down

0 comments on commit bb8a983

Please sign in to comment.