correctly calculate goalie average

This commit is contained in:
Jonathan Lamothe 2019-12-02 20:48:09 -05:00
parent d5ac42268f
commit 86c4fe316e
3 changed files with 20 additions and 8 deletions

View File

@ -5,6 +5,7 @@
- Allow lower case player names
- Don't show players without points in game report
- Removed unnecessary goalie statistics from game report
- Fixed goalie average calculation
## 0.7.0
- Shortened views to fit within 25 lines

View File

@ -1010,4 +1010,10 @@ addGoalieStats g1 g2 = GoalieStats
-- | Determines a goalie's average goals allowed per game.
gsAverage :: GoalieStats -> Rational
gsAverage gs = fromIntegral (gs^.gsGoalsAllowed) / fromIntegral (gs^.gsGames)
gsAverage gs = let
allowed = fromIntegral $ gs^.gsGoalsAllowed
mins = fromIntegral $ gs^.gsMinsPlayed
gLen = fromIntegral gameLength
in if mins == 0
then 0
else allowed / mins * gLen

View File

@ -813,16 +813,21 @@ addGoalieStatsSpec = describe "addGoalieStats" $ let
actual `shouldBe` expected
gsAverageSpec :: Spec
gsAverageSpec = describe "gsAverage" $ let
gsAverageSpec = describe "gsAverage" $ mapM_
(\(label, stats, expected) -> context label $
it ("should be " ++ show expected) $
gsAverage stats `shouldBe` expected)
-- label, stats, expected
[ ( "with minutes", gs, 3 % 2 )
, ( "no minutes", newGoalieStats , 0 )
]
where
gs = newGoalieStats
& gsGames .~ 2
& gsMinsPlayed .~ 2 * gameLength
& gsGoalsAllowed .~ 3
expected = 3 % 2
in it ("should be " ++ show expected) $
gsAverage gs `shouldBe` expected
joe :: Player
joe = newPlayer 2 "Joe" "center"