implemented awayScoreL

This commit is contained in:
Jonathan Lamothe 2019-08-22 14:33:39 -04:00
parent 2c2f9f5fc7
commit ef7d34110a
2 changed files with 40 additions and 2 deletions

View File

@ -43,6 +43,7 @@ module Mtlstats.Types (
-- ** ProgMode Lenses -- ** ProgMode Lenses
gameTypeL, gameTypeL,
homeScoreL, homeScoreL,
awayScoreL,
-- ** Database Lenses -- ** Database Lenses
dbPlayers, dbPlayers,
dbGoalies, dbGoalies,
@ -322,6 +323,15 @@ homeScoreL = lens
NewGame gs -> NewGame $ gs & homeScore .~ hs NewGame gs -> NewGame $ gs & homeScore .~ hs
_ -> NewGame $ newGameState & 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' -- | Constructor for a 'ProgState'
newProgState :: ProgState newProgState :: ProgState
newProgState = ProgState newProgState = ProgState

View File

@ -41,6 +41,7 @@ spec = describe "Mtlstats.Types" $ do
databaseSpec databaseSpec
gameTypeLSpec gameTypeLSpec
homeScoreLSpec homeScoreLSpec
awayScoreLSpec
Menu.spec Menu.spec
pPointsSpec :: Spec pPointsSpec :: Spec
@ -168,15 +169,42 @@ homeScoreLSpec = describe "homeScoreL" $ do
context "setter" $ do context "setter" $ do
context "unexpected mode" $ context "unexpected mode" $
it "should set the points" $ let it "should set home score" $ let
m = MainMenu & homeScoreL ?~ 0 m = MainMenu & homeScoreL ?~ 0
in m ^. homeScoreL `shouldBe` Just 0 in m ^. homeScoreL `shouldBe` Just 0
context "expected mode" $ context "expected mode" $
it "should set the points" $ let it "should set home score" $ let
m = NewGame newGameState & homeScoreL ?~ 0 m = NewGame newGameState & homeScoreL ?~ 0
in m ^. homeScoreL `shouldBe` Just 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 :: Player
player = newPlayer 1 "Joe" "centre" player = newPlayer 1 "Joe" "centre"
& pYtd . psGoals .~ 2 & pYtd . psGoals .~ 2