implemented gameWon
This commit is contained in:
parent
c15ad6a477
commit
7ee53ee8c1
|
@ -93,6 +93,7 @@ module Mtlstats.Types (
|
||||||
-- ** GameState Helpers
|
-- ** GameState Helpers
|
||||||
teamScore,
|
teamScore,
|
||||||
otherScore,
|
otherScore,
|
||||||
|
gameWon,
|
||||||
gameTied,
|
gameTied,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
pPoints
|
pPoints
|
||||||
|
@ -488,6 +489,12 @@ otherScore s = case s ^. gameType of
|
||||||
Just AwayGame -> s ^. homeScore
|
Just AwayGame -> s ^. homeScore
|
||||||
Nothing -> Nothing
|
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)
|
-- | Checks if the game has tied (retuns 'False' if unknown)
|
||||||
gameTied :: GameState -> Bool
|
gameTied :: GameState -> Bool
|
||||||
gameTied gs = case (,) <$> gs^.homeScore <*> gs^.awayScore of
|
gameTied gs = case (,) <$> gs^.homeScore <*> gs^.awayScore of
|
||||||
|
|
|
@ -43,6 +43,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
gameStateLSpec
|
gameStateLSpec
|
||||||
teamScoreSpec
|
teamScoreSpec
|
||||||
otherScoreSpec
|
otherScoreSpec
|
||||||
|
gameWonSpec
|
||||||
gameTiedSpec
|
gameTiedSpec
|
||||||
pPointsSpec
|
pPointsSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
@ -244,6 +245,34 @@ dbJSON = Object $ HM.fromList
|
||||||
, ( "away_game_stats", gameStatsJSON 2 )
|
, ( "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_
|
gameTiedSpec = describe "gameTied" $ mapM_
|
||||||
(\(home, away, expected) -> let
|
(\(home, away, expected) -> let
|
||||||
desc = "home score: " ++ show home ++
|
desc = "home score: " ++ show home ++
|
||||||
|
|
Loading…
Reference in New Issue
Block a user