implemented homeScoreL

This commit is contained in:
Jonathan Lamothe 2019-08-22 14:19:43 -04:00
parent 7b7529339a
commit 2c2f9f5fc7
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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