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 - Allow lower case player names
- Don't show players without points in game report - Don't show players without points in game report
- Removed unnecessary goalie statistics from game report - Removed unnecessary goalie statistics from game report
- Fixed goalie average calculation
## 0.7.0 ## 0.7.0
- Shortened views to fit within 25 lines - 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. -- | Determines a goalie's average goals allowed per game.
gsAverage :: GoalieStats -> Rational 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,15 +813,20 @@ addGoalieStatsSpec = describe "addGoalieStats" $ let
actual `shouldBe` expected actual `shouldBe` expected
gsAverageSpec :: Spec gsAverageSpec :: Spec
gsAverageSpec = describe "gsAverage" $ let gsAverageSpec = describe "gsAverage" $ mapM_
gs = newGoalieStats (\(label, stats, expected) -> context label $
& gsGames .~ 2 it ("should be " ++ show expected) $
& gsGoalsAllowed .~ 3 gsAverage stats `shouldBe` expected)
expected = 3 % 2 -- label, stats, expected
[ ( "with minutes", gs, 3 % 2 )
, ( "no minutes", newGoalieStats , 0 )
]
in it ("should be " ++ show expected) $ where
gsAverage gs `shouldBe` expected gs = newGoalieStats
& gsMinsPlayed .~ 2 * gameLength
& gsGoalsAllowed .~ 3
joe :: Player joe :: Player
joe = newPlayer 2 "Joe" "center" joe = newPlayer 2 "Joe" "center"