From ef7d34110afc066f0d7a8d782d9890ebc34065a1 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 22 Aug 2019 14:33:39 -0400 Subject: [PATCH] implemented awayScoreL --- src/Mtlstats/Types.hs | 10 ++++++++++ test/TypesSpec.hs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 9a02955..477273c 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -43,6 +43,7 @@ module Mtlstats.Types ( -- ** ProgMode Lenses gameTypeL, homeScoreL, + awayScoreL, -- ** Database Lenses dbPlayers, dbGoalies, @@ -322,6 +323,15 @@ homeScoreL = lens NewGame gs -> NewGame $ gs & homeScore .~ hs _ -> NewGame $ newGameState & homeScore .~ hs) +awayScoreL :: Lens' ProgMode (Maybe Int) +awayScoreL = lens + (\case + NewGame gs -> gs ^. awayScore + _ -> Nothing) + (\m as -> case m of + NewGame gs -> NewGame $ gs & awayScore .~ as + _ -> NewGame $ newGameState & awayScore .~ as) + -- | Constructor for a 'ProgState' newProgState :: ProgState newProgState = ProgState diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index c8d481b..b69c969 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -41,6 +41,7 @@ spec = describe "Mtlstats.Types" $ do databaseSpec gameTypeLSpec homeScoreLSpec + awayScoreLSpec Menu.spec pPointsSpec :: Spec @@ -168,15 +169,42 @@ homeScoreLSpec = describe "homeScoreL" $ do context "setter" $ do context "unexpected mode" $ - it "should set the points" $ let + it "should set home score" $ let m = MainMenu & homeScoreL ?~ 0 in m ^. homeScoreL `shouldBe` Just 0 context "expected mode" $ - it "should set the points" $ let + it "should set home score" $ let m = NewGame newGameState & homeScoreL ?~ 0 in m ^. homeScoreL `shouldBe` Just 0 +awayScoreLSpec :: Spec +awayScoreLSpec = describe "awayScoreL" $ do + + context "getter" $ do + + context "unexpected mode" $ + it "should return Nothing" $ + MainMenu ^. awayScoreL `shouldBe` Nothing + + context "expected mode" $ + it "should return 0" $ let + gs = newGameState & awayScore ?~ 0 + m = NewGame gs + in m ^. awayScoreL `shouldBe` Just 0 + + context "setter" $ do + + context "unexpected mode" $ + it "should set the away score" $ let + m = MainMenu & awayScoreL ?~ 0 + in m ^. awayScoreL `shouldBe` Just 0 + + context "expected mode" $ + it "should set the away score" $ let + m = NewGame newGameState & awayScoreL ?~ 0 + in m ^. awayScoreL `shouldBe` Just 0 + player :: Player player = newPlayer 1 "Joe" "centre" & pYtd . psGoals .~ 2