correctly calculate goalie average
This commit is contained in:
parent
d5ac42268f
commit
86c4fe316e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -813,15 +813,20 @@ addGoalieStatsSpec = describe "addGoalieStats" $ let
|
|||
actual `shouldBe` expected
|
||||
|
||||
gsAverageSpec :: Spec
|
||||
gsAverageSpec = describe "gsAverage" $ let
|
||||
gs = newGoalieStats
|
||||
& gsGames .~ 2
|
||||
& gsGoalsAllowed .~ 3
|
||||
gsAverageSpec = describe "gsAverage" $ mapM_
|
||||
(\(label, stats, expected) -> context label $
|
||||
it ("should be " ++ show expected) $
|
||||
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) $
|
||||
gsAverage gs `shouldBe` expected
|
||||
where
|
||||
gs = newGoalieStats
|
||||
& gsMinsPlayed .~ 2 * gameLength
|
||||
& gsGoalsAllowed .~ 3
|
||||
|
||||
joe :: Player
|
||||
joe = newPlayer 2 "Joe" "center"
|
||||
|
|
Loading…
Reference in New Issue
Block a user