refactored createPlayerStateLSpec to use lensSpec

This commit is contained in:
Jonathan Lamothe 2019-10-24 01:40:53 -04:00
parent 4519ba4732
commit 09c63da8bf

View File

@ -96,32 +96,25 @@ gameStateLSpec = describe "gameStateL" $ lensSpec gameStateL
where gs t = newGameState & gameType ?~ t where gs t = newGameState & gameType ?~ t
createPlayerStateLSpec :: Spec createPlayerStateLSpec :: Spec
createPlayerStateLSpec = describe "createPlayerStateL" $ do createPlayerStateLSpec = describe "createPlayerStateL" $ lensSpec createPlayerStateL
context "getters" $ do -- getters
context "state missing" $ let [ ( "missing state", MainMenu, newCreatePlayerState )
pm = MainMenu , ( "with state", CreatePlayer cps1, cps1 )
cps = pm^.createPlayerStateL ]
in it "should not have a number" $ -- setters
cps^.cpsNumber `shouldBe` Nothing [ ( "missing state", MainMenu, cps1 )
, ( "change state", CreatePlayer cps1, cps2 )
context "existing state" $ let , ( "clear state", CreatePlayer cps1, newCreatePlayerState )
pm = CreatePlayer $ newCreatePlayerState & cpsNumber ?~ 1 ]
cps = pm^.createPlayerStateL where
in it "should have a number of 1" $ cps1 = newCreatePlayerState
cps^.cpsNumber `shouldBe` Just 1 & cpsNumber ?~ 1
& cpsName .~ "Joe"
context "setters" $ do & cpsPosition .~ "centre"
context "state missing" $ let cps2 = newCreatePlayerState
pm = MainMenu & cpsNumber ?~ 2
pm' = pm & createPlayerStateL.cpsNumber ?~ 1 & cpsName .~ "Bob"
in it "should set the player number to 1" $ & cpsPosition .~ "defense"
pm'^.createPlayerStateL.cpsNumber `shouldBe` Just 1
context "existing state" $ let
pm = CreatePlayer $ newCreatePlayerState & cpsNumber ?~ 1
pm' = pm & createPlayerStateL.cpsNumber ?~ 2
in it "should set the player number to 2" $
pm'^.createPlayerStateL.cpsNumber `shouldBe` Just 2
teamScoreSpec :: Spec teamScoreSpec :: Spec
teamScoreSpec = describe "teamScore" $ do teamScoreSpec = describe "teamScore" $ do