implemented gameWon
This commit is contained in:
parent
c15ad6a477
commit
7ee53ee8c1
|
@ -93,6 +93,7 @@ module Mtlstats.Types (
|
|||
-- ** GameState Helpers
|
||||
teamScore,
|
||||
otherScore,
|
||||
gameWon,
|
||||
gameTied,
|
||||
-- ** Player Helpers
|
||||
pPoints
|
||||
|
@ -488,6 +489,12 @@ otherScore s = case s ^. gameType of
|
|||
Just AwayGame -> s ^. homeScore
|
||||
Nothing -> Nothing
|
||||
|
||||
-- | Checks if the game was won (returns 'False' if unknown)
|
||||
gameWon :: GameState -> Bool
|
||||
gameWon gs = case (,) <$> teamScore gs <*> otherScore gs of
|
||||
Just (team, other) -> team > other
|
||||
Nothing -> False
|
||||
|
||||
-- | Checks if the game has tied (retuns 'False' if unknown)
|
||||
gameTied :: GameState -> Bool
|
||||
gameTied gs = case (,) <$> gs^.homeScore <*> gs^.awayScore of
|
||||
|
|
|
@ -43,6 +43,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
gameStateLSpec
|
||||
teamScoreSpec
|
||||
otherScoreSpec
|
||||
gameWonSpec
|
||||
gameTiedSpec
|
||||
pPointsSpec
|
||||
Menu.spec
|
||||
|
@ -244,6 +245,34 @@ dbJSON = Object $ HM.fromList
|
|||
, ( "away_game_stats", gameStatsJSON 2 )
|
||||
]
|
||||
|
||||
gameWonSpec :: Spec
|
||||
gameWonSpec = describe "gameWon" $ mapM_
|
||||
(\(t, h, a, expected) -> let
|
||||
desc = "game type: " ++ show t ++
|
||||
", home score: " ++ show h ++
|
||||
", away score: " ++ show a
|
||||
gs = newGameState
|
||||
& gameType .~ t
|
||||
& homeScore .~ h
|
||||
& awayScore .~ a
|
||||
in context desc $
|
||||
it ("should be " ++ show expected) $
|
||||
gameWon gs `shouldBe` expected)
|
||||
-- gameType, homeScore, awayScore, expected
|
||||
[ ( Just HomeGame, Just 1, Just 1, False )
|
||||
, ( Just HomeGame, Just 1, Just 2, False )
|
||||
, ( Just HomeGame, Just 2, Just 1, True )
|
||||
, ( Just AwayGame, Just 1, Just 1, False )
|
||||
, ( Just AwayGame, Just 1, Just 2, True )
|
||||
, ( Just AwayGame, Just 2, Just 1, False )
|
||||
, ( Nothing, Just 1, Just 2, False )
|
||||
, ( Just HomeGame, Nothing, Just 1, False )
|
||||
, ( Just AwayGame, Nothing, Just 1, False )
|
||||
, ( Just HomeGame, Just 1, Nothing, False )
|
||||
, ( Just AwayGame, Just 1, Nothing, False )
|
||||
, ( Nothing, Nothing, Nothing, False )
|
||||
]
|
||||
|
||||
gameTiedSpec = describe "gameTied" $ mapM_
|
||||
(\(home, away, expected) -> let
|
||||
desc = "home score: " ++ show home ++
|
||||
|
|
Loading…
Reference in New Issue
Block a user