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