record active flag on player creation

This commit is contained in:
Jonathan Lamothe 2020-02-13 23:40:43 -05:00
parent 960fbb3443
commit e28ef1ff0e
2 changed files with 27 additions and 15 deletions

View File

@ -163,11 +163,13 @@ addPlayer s = fromMaybe s $ do
let cps = s^.progMode.createPlayerStateL
num <- cps^.cpsNumber
rFlag <- cps^.cpsRookieFlag
aFlag <- cps^.cpsActiveFlag
let
name = cps^.cpsName
pos = cps^.cpsPosition
player = newPlayer num name pos
& pRookie .~ rFlag
& pActive .~ aFlag
Just $ s & database.dbPlayers
%~ (++[player])

View File

@ -321,30 +321,40 @@ addPlayerSpec = describe "addPlayer" $ mapM_
ps' = addPlayer ps
in ps'^.database.dbPlayers `shouldBe` players)
-- label, expectation, progMode, players
[ ( "wrong mode", failure, MainMenu, [joe] )
, ( "missing number", failure, noNum, [joe] )
, ( "missing rookie flag", failure, noRookie, [joe] )
, ( "rookie", success, mkRookie, [joe, rookie] )
, ( "normal player", success, mkNormal, [joe, normal] )
-- label, expectation, progMode, players
[ ( "wrong mode", failure, MainMenu, [joe] )
, ( "missing number", failure, noNum, [joe] )
, ( "missing rookie flag", failure, noRookie, [joe] )
, ( "missing active flag", failure, noActive, [joe] )
, ( "rookie", success, mkRookie, [joe, rookie] )
, ( "retired", success, mkRetired, [joe, retired] )
, ( "normal player", success, mkNormal, [joe, normal] )
]
where
failure = "should not create the player"
success = "should create the player"
noNum = mkpm Nothing (Just False)
noRookie = mkpm (Just 3) Nothing
mkRookie = mkpm (Just 3) (Just True)
mkNormal = mkpm (Just 3) (Just False)
noNum = mkpm Nothing (Just False) (Just True)
noRookie = mkpm (Just 3) Nothing (Just True)
noActive = mkpm (Just 3) (Just False) Nothing
mkRookie = mkpm (Just 3) (Just True) (Just True)
mkRetired = mkpm (Just 3) (Just False) (Just False)
mkNormal = mkpm (Just 3) (Just False) (Just True)
joe = newPlayer 2 "Joe" "centre"
rookie = bob True
normal = bob False
bob rf = newPlayer 3 "Bob" "defense" & pRookie .~ rf
mkpm n rf = CreatePlayer $ newCreatePlayerState
rookie = bob True True
retired = bob False False
normal = bob False True
bob r a = newPlayer 3 "Bob" "defense"
& pRookie .~ r
& pActive .~ a
mkpm n r a = CreatePlayer $ newCreatePlayerState
& cpsNumber .~ n
& cpsName .~ "Bob"
& cpsPosition .~ "defense"
& cpsRookieFlag .~ rf
& cpsRookieFlag .~ r
& cpsActiveFlag .~ a
addGoalieSpec :: Spec
addGoalieSpec = describe "addGoalie" $ mapM_