From 2c2f9f5fc75f212bfa4b8242f2c28ec990369c9c Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 22 Aug 2019 14:19:43 -0400 Subject: [PATCH] implemented homeScoreL --- src/Mtlstats/Types.hs | 10 ++++++++++ test/TypesSpec.hs | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index f3bfcb4..9a02955 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -42,6 +42,7 @@ module Mtlstats.Types ( awayScore, -- ** ProgMode Lenses gameTypeL, + homeScoreL, -- ** Database Lenses dbPlayers, dbGoalies, @@ -312,6 +313,15 @@ gameTypeL = lens NewGame gs -> NewGame $ gs & gameType .~ gt _ -> NewGame $ newGameState & gameType .~ gt) +homeScoreL :: Lens' ProgMode (Maybe Int) +homeScoreL = lens + (\case + NewGame gs -> gs ^. homeScore + _ -> Nothing) + (\m hs -> case m of + NewGame gs -> NewGame $ gs & homeScore .~ hs + _ -> NewGame $ newGameState & homeScore .~ hs) + -- | Constructor for a 'ProgState' newProgState :: ProgState newProgState = ProgState diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 89b5a5e..c8d481b 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -40,6 +40,7 @@ spec = describe "Mtlstats.Types" $ do goalieSpec databaseSpec gameTypeLSpec + homeScoreLSpec Menu.spec pPointsSpec :: Spec @@ -150,6 +151,32 @@ gameTypeLSpec = describe "gameTypeL" $ do in m ^. gameTypeL `shouldBe` Just t) [HomeGame, AwayGame] +homeScoreLSpec = describe "homeScoreL" $ do + + context "getter" $ do + + context "unexpected mode" $ + it "should return Nothing" $ + MainMenu ^. homeScoreL `shouldBe` Nothing + + context "expected mode" $ + it "should return 0" $ let + gs = newGameState & homeScore ?~ 0 + m = NewGame gs + in m ^. homeScoreL `shouldBe` Just 0 + + context "setter" $ do + + context "unexpected mode" $ + it "should set the points" $ let + m = MainMenu & homeScoreL ?~ 0 + in m ^. homeScoreL `shouldBe` Just 0 + + context "expected mode" $ + it "should set the points" $ let + m = NewGame newGameState & homeScoreL ?~ 0 + in m ^. homeScoreL `shouldBe` Just 0 + player :: Player player = newPlayer 1 "Joe" "centre" & pYtd . psGoals .~ 2