From 9b07c6d2497d4f8147cad3a145ab898a20e668ff Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 23:55:00 -0500 Subject: [PATCH] record active flag on goalie creation --- src/Mtlstats/Actions.hs | 2 ++ test/ActionsSpec.hs | 54 ++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 08d08ee..582f0e6 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -179,10 +179,12 @@ addGoalie s = fromMaybe s $ do let cgs = s^.progMode.createGoalieStateL num <- cgs^.cgsNumber rFlag <- cgs^.cgsRookieFlag + aFlag <- cgs^.cgsActiveFlag let name = cgs^.cgsName goalie = newGoalie num name & gRookie .~ rFlag + & gActive .~ aFlag Just $ s & database.dbGoalies %~ (++[goalie]) diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 718fe27..1f18d5b 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -341,11 +341,11 @@ addPlayerSpec = describe "addPlayer" $ mapM_ mkRetired = mkpm (Just 3) (Just False) (Just False) mkNormal = mkpm (Just 3) (Just False) (Just True) joe = newPlayer 2 "Joe" "centre" - rookie = bob True True - retired = bob False False - normal = bob False True + rookie = player True True + retired = player False False + normal = player False True - bob r a = newPlayer 3 "Bob" "defense" + player r a = newPlayer 3 "Bob" "defense" & pRookie .~ r & pActive .~ a @@ -366,29 +366,39 @@ addGoalieSpec = describe "addGoalie" $ mapM_ ps' = addGoalie ps in ps'^.database.dbGoalies `shouldBe` goalies) - -- label, expectation, progMode, expected goalies - [ ( "wrong mode", failure, MainMenu, [joe] ) - , ( "no number", failure, noNum, [joe] ) - , ( "no rookie flag", failure, noRookie, [joe] ) - , ( "rookie", success, mkRookie, [joe, rookie] ) - , ( "normal goalie", success, mkNormal, [joe, normal] ) + -- label, expectation, progMode, expected goalies + [ ( "wrong mode", failure, MainMenu, [joe] ) + , ( "no number", failure, noNum, [joe] ) + , ( "no rookie flag", failure, noRookie, [joe] ) + , ( "no active flag", failure, noActive, [joe] ) + , ( "rookie", success, mkRookie, [joe, rookie] ) + , ( "retired", success, mkRetired, [joe, retired] ) + , ( "normal goalie", success, mkNormal, [joe, normal] ) ] where - failure = "should not create the goalie" - success = "should create the goalie" - noNum = cgs Nothing (Just False) - noRookie = cgs (Just 3) Nothing - mkRookie = cgs (Just 3) (Just True) - mkNormal = cgs (Just 3) (Just False) - joe = newGoalie 2 "Joe" - rookie = bob True - normal = bob False - bob r = newGoalie 3 "Bob" & gRookie .~ r - cgs n rf = CreateGoalie $ newCreateGoalieState + failure = "should not create the goalie" + success = "should create the goalie" + noNum = cgs Nothing (Just False) (Just True) + noRookie = cgs (Just 3) Nothing (Just True) + noActive = cgs (Just 3) (Just False) Nothing + mkRookie = cgs (Just 3) (Just True) (Just True) + mkRetired = cgs (Just 3) (Just False) (Just False) + mkNormal = cgs (Just 3) (Just False) (Just True) + joe = newGoalie 2 "Joe" + rookie = goalie True True + retired = goalie False False + normal = goalie False True + + goalie r a = newGoalie 3 "Bob" + & gRookie .~ r + & gActive .~ a + + cgs n r a = CreateGoalie $ newCreateGoalieState & cgsNumber .~ n & cgsName .~ "Bob" - & cgsRookieFlag .~ rf + & cgsRookieFlag .~ r + & cgsActiveFlag .~ a resetCreatePlayerStateSpec :: Spec resetCreatePlayerStateSpec = describe "resetCreatePlayerState" $ let