From 5098e09982b79c813530946457a01b83a3ef8869 Mon Sep 17 00:00:00 2001 From: Alexander Lentner Date: Thu, 15 Apr 2021 14:26:47 +0200 Subject: [PATCH] Handle draw gap differently --- src/CalculationModel.php | 1 + src/DefaultCalculationModel.php | 5 +++++ src/MatchCalculator.php | 15 ++++++++++++++- tests/MatchCalculatorTest.php | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/CalculationModel.php b/src/CalculationModel.php index c9b1947..2c12fb7 100644 --- a/src/CalculationModel.php +++ b/src/CalculationModel.php @@ -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; diff --git a/src/DefaultCalculationModel.php b/src/DefaultCalculationModel.php index b62a675..4b734e4 100644 --- a/src/DefaultCalculationModel.php +++ b/src/DefaultCalculationModel.php @@ -14,6 +14,11 @@ public function getPointsForExactGap(): int return 2; } + public function getPointsForDrawGap(): int + { + return 1; + } + public function getPointsForTendency(): int { return 1; diff --git a/src/MatchCalculator.php b/src/MatchCalculator.php index 4a32179..8769362 100644 --- a/src/MatchCalculator.php +++ b/src/MatchCalculator.php @@ -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; } @@ -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()) { diff --git a/tests/MatchCalculatorTest.php b/tests/MatchCalculatorTest.php index 318ef3e..509d855 100644 --- a/tests/MatchCalculatorTest.php +++ b/tests/MatchCalculatorTest.php @@ -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); @@ -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);