From e3d5af5f88e04aef58fc7a47fbe857938fa3453e Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 28 Nov 2019 05:59:06 -0500 Subject: [PATCH] implemented addGoalieStats --- src/Mtlstats/Types.hs | 10 +++++++++- test/TypesSpec.hs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 1c7849e..4d8f723 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -996,7 +996,15 @@ goalieIsActive g = g^.gYtd.gsMinsPlayed /= 0 -- | Adds two sets of 'GoalieStats' addGoalieStats :: GoalieStats -> GoalieStats -> GoalieStats -addGoalieStats = undefined +addGoalieStats g1 g2 = GoalieStats + { _gsGames = g1^.gsGames + g2^.gsGames + , _gsMinsPlayed = g1^.gsMinsPlayed + g2^.gsMinsPlayed + , _gsGoalsAllowed = g1^.gsGoalsAllowed + g2^.gsGoalsAllowed + , _gsShutouts = g1^.gsShutouts + g2^.gsShutouts + , _gsWins = g1^.gsWins + g2^.gsWins + , _gsLosses = g1^.gsLosses + g2^.gsLosses + , _gsTies = g1^.gsTies + g2^.gsTies + } -- | Determines a goalie's average goals allowed per game. gsAverage :: GoalieStats -> Rational diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index a75e74a..e2c6f57 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -79,6 +79,7 @@ spec = describe "Mtlstats.Types" $ do goalieSearchExactSpec goalieSummarySpec goalieIsActiveSpec + addGoalieStatsSpec Menu.spec playerSpec :: Spec @@ -772,6 +773,43 @@ goalieIsActiveSpec = describe "goalieIsActive" $ mapM_ active = inactive & gYtd.gsMinsPlayed .~ 1 +addGoalieStatsSpec :: Spec +addGoalieStatsSpec = describe "addGoalieStats" $ let + g1 = GoalieStats + { _gsGames = 1 + , _gsMinsPlayed = 2 + , _gsGoalsAllowed = 3 + , _gsShutouts = 4 + , _gsWins = 5 + , _gsLosses = 6 + , _gsTies = 7 + } + + g2 = GoalieStats + { _gsGames = 8 + , _gsMinsPlayed = 9 + , _gsGoalsAllowed = 10 + , _gsShutouts = 11 + , _gsWins = 12 + , _gsLosses = 13 + , _gsTies = 14 + } + + expected = GoalieStats + { _gsGames = 9 + , _gsMinsPlayed = 11 + , _gsGoalsAllowed = 13 + , _gsShutouts = 15 + , _gsWins = 17 + , _gsLosses = 19 + , _gsTies = 21 + } + + actual = g1 `addGoalieStats` g2 + + in it ("should be " ++ show expected) $ + actual `shouldBe` expected + joe :: Player joe = newPlayer 2 "Joe" "center"