implemented gameTied helper function
This commit is contained in:
parent
e834019fc9
commit
c15ad6a477
|
@ -93,6 +93,7 @@ module Mtlstats.Types (
|
||||||
-- ** GameState Helpers
|
-- ** GameState Helpers
|
||||||
teamScore,
|
teamScore,
|
||||||
otherScore,
|
otherScore,
|
||||||
|
gameTied,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
pPoints
|
pPoints
|
||||||
) where
|
) where
|
||||||
|
@ -487,6 +488,12 @@ otherScore s = case s ^. gameType of
|
||||||
Just AwayGame -> s ^. homeScore
|
Just AwayGame -> s ^. homeScore
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
|
|
||||||
|
-- | Checks if the game has tied (retuns 'False' if unknown)
|
||||||
|
gameTied :: GameState -> Bool
|
||||||
|
gameTied gs = case (,) <$> gs^.homeScore <*> gs^.awayScore of
|
||||||
|
Just (home, away) -> home == away
|
||||||
|
Nothing -> False
|
||||||
|
|
||||||
-- | Calculates a player's points
|
-- | Calculates a player's points
|
||||||
pPoints :: PlayerStats -> Int
|
pPoints :: PlayerStats -> Int
|
||||||
pPoints s = s^.psGoals + s^.psAssists
|
pPoints s = s^.psGoals + s^.psAssists
|
||||||
|
|
|
@ -43,6 +43,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
gameStateLSpec
|
gameStateLSpec
|
||||||
teamScoreSpec
|
teamScoreSpec
|
||||||
otherScoreSpec
|
otherScoreSpec
|
||||||
|
gameTiedSpec
|
||||||
pPointsSpec
|
pPointsSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
|
||||||
|
@ -243,6 +244,23 @@ dbJSON = Object $ HM.fromList
|
||||||
, ( "away_game_stats", gameStatsJSON 2 )
|
, ( "away_game_stats", gameStatsJSON 2 )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
gameTiedSpec = describe "gameTied" $ mapM_
|
||||||
|
(\(home, away, expected) -> let
|
||||||
|
desc = "home score: " ++ show home ++
|
||||||
|
", away score: " ++ show away
|
||||||
|
gs = newGameState
|
||||||
|
& homeScore .~ home
|
||||||
|
& awayScore .~ away
|
||||||
|
in context desc $
|
||||||
|
it ("should be " ++ show expected) $
|
||||||
|
gameTied gs `shouldBe` expected)
|
||||||
|
[ ( Nothing, Nothing, False )
|
||||||
|
, ( Nothing, Just 1, False )
|
||||||
|
, ( Just 1, Nothing, False )
|
||||||
|
, ( Just 1, Just 1, True )
|
||||||
|
, ( Just 1, Just 2, False )
|
||||||
|
]
|
||||||
|
|
||||||
pPointsSpec :: Spec
|
pPointsSpec :: Spec
|
||||||
pPointsSpec = describe "pPoints" $ mapM_
|
pPointsSpec = describe "pPoints" $ mapM_
|
||||||
(\(goals, assists, points) -> let
|
(\(goals, assists, points) -> let
|
||||||
|
|
Loading…
Reference in New Issue
Block a user