implemented gameLost
This commit is contained in:
parent
3fe2ff10f6
commit
a9d952b97b
|
@ -95,6 +95,7 @@ module Mtlstats.Types (
|
|||
teamScore,
|
||||
otherScore,
|
||||
gameWon,
|
||||
gameLost,
|
||||
gameTied,
|
||||
-- ** Player Helpers
|
||||
pPoints
|
||||
|
@ -497,6 +498,10 @@ otherScore s = case s ^. gameType of
|
|||
gameWon :: GameState -> Maybe Bool
|
||||
gameWon gs = (>) <$> teamScore gs <*> otherScore gs
|
||||
|
||||
-- | Checks if the game was lost
|
||||
gameLost :: GameState -> Maybe Bool
|
||||
gameLost gs = (<) <$> teamScore gs <*> otherScore gs
|
||||
|
||||
-- | Checks if the game has tied
|
||||
gameTied :: GameState -> Maybe Bool
|
||||
gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
|
||||
|
|
|
@ -44,6 +44,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
teamScoreSpec
|
||||
otherScoreSpec
|
||||
gameWonSpec
|
||||
gameLostSpec
|
||||
gameTiedSpec
|
||||
pPointsSpec
|
||||
Menu.spec
|
||||
|
@ -273,6 +274,34 @@ gameWonSpec = describe "gameWon" $ mapM_
|
|||
, ( Nothing, Nothing, Nothing, Nothing )
|
||||
]
|
||||
|
||||
gameLostSpec :: Spec
|
||||
gameLostSpec = describe "gameLost" $ 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) $
|
||||
gameLost gs `shouldBe` expected)
|
||||
-- gameType, homeScore, awayScore, expected
|
||||
[ ( Just HomeGame, Just 1, Just 1, Just False )
|
||||
, ( Just HomeGame, Just 1, Just 2, Just True )
|
||||
, ( Just HomeGame, Just 2, Just 1, Just False )
|
||||
, ( Just AwayGame, Just 1, Just 1, Just False )
|
||||
, ( Just AwayGame, Just 1, Just 2, Just False )
|
||||
, ( Just AwayGame, Just 2, Just 1, Just True )
|
||||
, ( Nothing, Just 1, Just 2, Nothing )
|
||||
, ( Just HomeGame, Nothing, Just 1, Nothing )
|
||||
, ( Just AwayGame, Nothing, Just 1, Nothing )
|
||||
, ( Just HomeGame, Just 1, Nothing, Nothing )
|
||||
, ( Just AwayGame, Just 1, Nothing, Nothing )
|
||||
, ( Nothing, Nothing, Nothing, Nothing )
|
||||
]
|
||||
|
||||
gameTiedSpec :: Spec
|
||||
gameTiedSpec = describe "gameTied" $ mapM_
|
||||
(\(home, away, expected) -> let
|
||||
|
|
Loading…
Reference in New Issue
Block a user