implemented gmsPoints

This commit is contained in:
Jonathan Lamothe 2019-08-30 18:57:56 -04:00
parent 4c13cc9103
commit 9e855d9672
2 changed files with 27 additions and 0 deletions

View File

@ -97,6 +97,8 @@ module Mtlstats.Types (
gameWon,
gameLost,
gameTied,
-- ** GameStats Helpers
gmsPoints,
-- ** Player Helpers
pPoints
) where
@ -506,6 +508,10 @@ gameLost gs = (<) <$> teamScore gs <*> otherScore gs
gameTied :: GameState -> Maybe Bool
gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
-- | Calculates the number of points
gmsPoints :: GameStats -> Int
gmsPoints gs = 2 * gs^.gmsWins + gs^. gmsOvertime
-- | Calculates a player's points
pPoints :: PlayerStats -> Int
pPoints s = s^.psGoals + s^.psAssists

View File

@ -46,6 +46,7 @@ spec = describe "Mtlstats.Types" $ do
gameWonSpec
gameLostSpec
gameTiedSpec
gmsPointsSpec
pPointsSpec
Menu.spec
@ -320,6 +321,26 @@ gameTiedSpec = describe "gameTied" $ mapM_
, ( Just 1, Just 2, Just False )
]
gmsPointsSpec :: Spec
gmsPointsSpec = describe "gmsPoints" $ mapM_
(\(w, l, ot, expected) -> let
gs = GameStats
{ _gmsWins = w
, _gmsLosses = l
, _gmsOvertime = ot
}
in context (show gs) $
it ("should be " ++ show expected) $
gmsPoints gs `shouldBe` expected)
-- wins, losses, overtime, expected
[ ( 0, 0, 0, 0 )
, ( 1, 0, 0, 2 )
, ( 0, 1, 0, 0 )
, ( 0, 1, 1, 1 )
, ( 1, 1, 1, 3 )
, ( 2, 4, 3, 7 )
]
pPointsSpec :: Spec
pPointsSpec = describe "pPoints" $ mapM_
(\(goals, assists, points) -> let