added _otherTeam with its associated lenses
This commit is contained in:
parent
2a2189c7d1
commit
0f9f76ce4e
|
@ -41,10 +41,12 @@ module Mtlstats.Types (
|
||||||
inputBuffer,
|
inputBuffer,
|
||||||
-- ** GameState Lenses
|
-- ** GameState Lenses
|
||||||
gameType,
|
gameType,
|
||||||
|
otherTeam,
|
||||||
homeScore,
|
homeScore,
|
||||||
awayScore,
|
awayScore,
|
||||||
-- ** ProgMode Lenses
|
-- ** ProgMode Lenses
|
||||||
gameTypeL,
|
gameTypeL,
|
||||||
|
otherTeamL,
|
||||||
homeScoreL,
|
homeScoreL,
|
||||||
awayScoreL,
|
awayScoreL,
|
||||||
-- ** Database Lenses
|
-- ** Database Lenses
|
||||||
|
@ -123,6 +125,8 @@ data ProgState = ProgState
|
||||||
data GameState = GameState
|
data GameState = GameState
|
||||||
{ _gameType :: Maybe GameType
|
{ _gameType :: Maybe GameType
|
||||||
-- ^ The type of game (home/away)
|
-- ^ The type of game (home/away)
|
||||||
|
, _otherTeam :: String
|
||||||
|
-- ^ The name of the other team
|
||||||
, _homeScore :: Maybe Int
|
, _homeScore :: Maybe Int
|
||||||
-- ^ The home team's score
|
-- ^ The home team's score
|
||||||
, _awayScore :: Maybe Int
|
, _awayScore :: Maybe Int
|
||||||
|
@ -341,6 +345,15 @@ gameTypeL = lens
|
||||||
NewGame gs -> NewGame $ gs & gameType .~ gt
|
NewGame gs -> NewGame $ gs & gameType .~ gt
|
||||||
_ -> NewGame $ newGameState & gameType .~ gt)
|
_ -> NewGame $ newGameState & gameType .~ gt)
|
||||||
|
|
||||||
|
otherTeamL :: Lens' ProgMode String
|
||||||
|
otherTeamL = lens
|
||||||
|
(\case
|
||||||
|
NewGame gs -> gs ^. otherTeam
|
||||||
|
_ -> "")
|
||||||
|
(\m ot -> case m of
|
||||||
|
NewGame gs -> NewGame $ gs & otherTeam .~ ot
|
||||||
|
_ -> NewGame $ newGameState & otherTeam .~ ot)
|
||||||
|
|
||||||
homeScoreL :: Lens' ProgMode (Maybe Int)
|
homeScoreL :: Lens' ProgMode (Maybe Int)
|
||||||
homeScoreL = lens
|
homeScoreL = lens
|
||||||
(\case
|
(\case
|
||||||
|
@ -371,6 +384,7 @@ newProgState = ProgState
|
||||||
newGameState :: GameState
|
newGameState :: GameState
|
||||||
newGameState = GameState
|
newGameState = GameState
|
||||||
{ _gameType = Nothing
|
{ _gameType = Nothing
|
||||||
|
, _otherTeam = ""
|
||||||
, _homeScore = Nothing
|
, _homeScore = Nothing
|
||||||
, _awayScore = Nothing
|
, _awayScore = Nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
goalieSpec
|
goalieSpec
|
||||||
databaseSpec
|
databaseSpec
|
||||||
gameTypeLSpec
|
gameTypeLSpec
|
||||||
|
otherTeamLSpec
|
||||||
homeScoreLSpec
|
homeScoreLSpec
|
||||||
awayScoreLSpec
|
awayScoreLSpec
|
||||||
teamScoreSpec
|
teamScoreSpec
|
||||||
|
@ -130,6 +131,32 @@ gameTypeLSpec = describe "gameTypeL" $ do
|
||||||
in m ^. gameTypeL `shouldBe` Just t)
|
in m ^. gameTypeL `shouldBe` Just t)
|
||||||
[HomeGame, AwayGame]
|
[HomeGame, AwayGame]
|
||||||
|
|
||||||
|
otherTeamLSpec :: Spec
|
||||||
|
otherTeamLSpec = describe "otherTeamL" $ do
|
||||||
|
|
||||||
|
context "getter" $ do
|
||||||
|
|
||||||
|
context "unexpected mode" $
|
||||||
|
it "should return an empty string" $
|
||||||
|
MainMenu ^. otherTeamL `shouldBe` ""
|
||||||
|
|
||||||
|
context "expected mode" $
|
||||||
|
it "should return \"foo\"" $ let
|
||||||
|
m = NewGame $ newGameState & otherTeam .~ "foo"
|
||||||
|
in m ^. otherTeamL `shouldBe` "foo"
|
||||||
|
|
||||||
|
context "setter" $ do
|
||||||
|
|
||||||
|
context "unexpected mode" $
|
||||||
|
it "should set the value" $ let
|
||||||
|
m = MainMenu & otherTeamL .~ "foo"
|
||||||
|
in m ^. otherTeamL `shouldBe` "foo"
|
||||||
|
|
||||||
|
context "expected mode" $
|
||||||
|
it "should set the value" $ let
|
||||||
|
m = NewGame newGameState & otherTeamL .~ "foo"
|
||||||
|
in m ^. otherTeamL `shouldBe` "foo"
|
||||||
|
|
||||||
homeScoreLSpec :: Spec
|
homeScoreLSpec :: Spec
|
||||||
homeScoreLSpec = describe "homeScoreL" $ do
|
homeScoreLSpec = describe "homeScoreL" $ do
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user