implemented gmsGames

This commit is contained in:
Jonathan Lamothe 2019-09-03 14:15:29 -04:00
parent 84cb2c8c19
commit 258cf59417
2 changed files with 25 additions and 0 deletions

View File

@ -103,6 +103,7 @@ module Mtlstats.Types (
gameLost,
gameTied,
-- ** GameStats Helpers
gmsGames,
gmsPoints,
addGameStats,
-- ** Player Helpers
@ -541,6 +542,10 @@ gameLost gs = (<) <$> teamScore gs <*> otherScore gs
gameTied :: GameState -> Maybe Bool
gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
-- | Calculates the number of games played
gmsGames :: GameStats -> Int
gmsGames gs = gs^.gmsWins + gs^.gmsLosses
-- | Calculates the number of points
gmsPoints :: GameStats -> Int
gmsPoints gs = 2 * gs^.gmsWins + gs^. gmsOvertime

View File

@ -49,6 +49,7 @@ spec = describe "Mtlstats.Types" $ do
gameWonSpec
gameLostSpec
gameTiedSpec
gmsGamesSpec
gmsPointsSpec
addGameStatsSpec
pPointsSpec
@ -363,6 +364,25 @@ gameTiedSpec = describe "gameTied" $ mapM_
, ( Just 1, Just 2, Just False )
]
gmsGamesSpec :: Spec
gmsGamesSpec = describe "gmsGames" $ mapM_
(\(w, l, expected) -> let
desc = "wins: " ++ show w ++
", losses: " ++ show l
gs = newGameStats
& gmsWins .~ w
& gmsLosses .~ l
in context desc $
it ("should be " ++ show expected) $
gmsGames gs `shouldBe` expected)
-- wins, losses, expected
[ ( 0, 0, 0 )
, ( 1, 0, 1 )
, ( 0, 1, 1 )
, ( 1, 1, 2 )
, ( 2, 3, 5 )
]
gmsPointsSpec :: Spec
gmsPointsSpec = describe "gmsPoints" $ mapM_
(\(w, l, ot, expected) -> let