Skip to content

Commit

Permalink
Handle draw gap differently
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lentner committed Apr 15, 2021
1 parent bd999fe commit 5098e09
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/CalculationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface CalculationModel
{
public function getPointsForExactGuess(): int;
public function getPointsForExactGap(): int;
public function getPointsForDrawGap(): int;
public function getPointsForTendency(): int;
public function getPointsForWrongGuess(): int;
public function getPointsForNoGuess(): int;
Expand Down
5 changes: 5 additions & 0 deletions src/DefaultCalculationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function getPointsForExactGap(): int
return 2;
}

public function getPointsForDrawGap(): int
{
return 1;
}

public function getPointsForTendency(): int
{
return 1;
Expand Down
15 changes: 14 additions & 1 deletion src/MatchCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function process(Score $result, ?Score $guess): MatchCalculator

if ($this->isExactGap()) {
$this->evaluatedResult->setToGap();
$this->raisePoints($this->calculationModel->getPointsForExactGap());
if ($this->isDrawGap()) {
$this->raisePoints($this->calculationModel->getPointsForDrawGap());
} else {
$this->raisePoints($this->calculationModel->getPointsForExactGap());
}
return $this;
}

Expand Down Expand Up @@ -96,6 +100,15 @@ private function isExactGap(): bool
return false;
}

private function isDrawGap(): bool
{
if (($this->result->margin() === $this->guess->margin()) && $this->result->isDraw() && $this->guess->isDraw()) {
return true;
}

return false;
}

private function isCorrectTendency(): bool
{
if ($this->result->isHomeWin() && $this->guess->isHomeWin()) {
Expand Down
4 changes: 2 additions & 2 deletions tests/MatchCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testProcessDraw(): void

$guess = $this->getScore(1, 1);
$evaluatedResult = $this->matchCalculator->process($result, $guess)->get();
$this->assertEquals((float) $this->calculationModel->getPointsForExactGap(), $evaluatedResult->getPoints());
$this->assertEquals((float) $this->calculationModel->getPointsForDrawGap(), $evaluatedResult->getPoints());
$this->assertEquals($evaluatedResult->isExact(), false);
$this->assertEquals($evaluatedResult->isGap(), true);
$this->assertEquals($evaluatedResult->isTendency(), false);
Expand All @@ -115,7 +115,7 @@ public function testProcessDraw(): void

$guess = $this->getScore(3, 3);
$evaluatedResult = $this->matchCalculator->process($result, $guess)->get();
$this->assertEquals((float) $this->calculationModel->getPointsForExactGap(), $evaluatedResult->getPoints());
$this->assertEquals((float) $this->calculationModel->getPointsForDrawGap(), $evaluatedResult->getPoints());
$this->assertEquals($evaluatedResult->isExact(), false);
$this->assertEquals($evaluatedResult->isGap(), true);
$this->assertEquals($evaluatedResult->isTendency(), false);
Expand Down

0 comments on commit 5098e09

Please sign in to comment.