From a9d952b97b0b43564cc77058dd14579c6c05cb8f Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 30 Aug 2019 00:44:40 -0400 Subject: [PATCH] implemented gameLost --- src/Mtlstats/Types.hs | 5 +++++ test/TypesSpec.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 49c05fc..96fcd72 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -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 diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 1af9999..8b8fe52 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -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