implemented awardGoalAssists

This commit is contained in:
Jonathan Lamothe 2019-09-27 01:39:50 -04:00
parent 11fcbfcbdd
commit 669c854f4f
2 changed files with 63 additions and 1 deletions

View File

@ -153,7 +153,21 @@ addPlayer s = fromMaybe s $ do
-- | Awards the goal and assists to the players -- | Awards the goal and assists to the players
recordGoalAssists :: ProgState -> ProgState recordGoalAssists :: ProgState -> ProgState
recordGoalAssists = undefined recordGoalAssists ps = fromMaybe ps $ do
let
gs = ps^.progMode.gameStateL
players = ps^.database.dbPlayers
(goalId, _) <- playerSearchExact (gs^.goalBy) players
assistIds <- mapM
(\name -> fst <$> playerSearchExact name players)
(gs^.assistsBy)
Just $ ps
& awardGoal goalId
& (\s -> foldr awardAssist s assistIds)
& progMode.gameStateL
%~ (goalBy .~ "")
. (assistsBy .~ [])
. (pointsAccounted %~ succ)
-- | Awards a goal to a player -- | Awards a goal to a player
awardGoal awardGoal

View File

@ -41,6 +41,7 @@ spec = describe "Mtlstats.Actions" $ do
validateGameDateSpec validateGameDateSpec
createPlayerSpec createPlayerSpec
addPlayerSpec addPlayerSpec
recordGoalAssistsSpec
awardGoalSpec awardGoalSpec
awardAssistSpec awardAssistSpec
@ -359,6 +360,53 @@ addPlayerSpec = describe "addPlayer" $ do
s' = addPlayer $ s MainMenu s' = addPlayer $ s MainMenu
in s'^.database.dbPlayers `shouldBe` [p2] in s'^.database.dbPlayers `shouldBe` [p2]
recordGoalAssistsSpec :: Spec
recordGoalAssistsSpec = describe "recordGoalAssists" $ do
let
joe = newPlayer 1 "Joe" "centre"
bob = newPlayer 2 "Bob" "defense"
steve = newPlayer 3 "Steve" "forward"
dave = newPlayer 4 "Dave" "somewhere"
ps
= newProgState
& database.dbPlayers .~ [joe, bob, steve, dave]
& progMode.gameStateL
%~ (goalBy .~ "Joe")
. (assistsBy .~ ["Bob", "Steve"])
& recordGoalAssists
mapM_
(\(name, n, ytdg, ltg, ytda, lta) -> context name $ do
let player = (ps^.database.dbPlayers) !! n
it ("should set the year-to-date goals to " ++ show ytdg) $
player^.pYtd.psGoals `shouldBe` ytdg
it ("should set the lifetime goals to " ++ show ltg) $
player^.pLifetime.psGoals `shouldBe` ltg
it ("should set the year-to-date assists to " ++ show ytda) $
player^.pYtd.psAssists `shouldBe` ytda
it ("should set the lifetime assists to " ++ show lta) $
player^.pLifetime.psAssists `shouldBe` lta)
-- name, index, ytd goals, lt goals, ytd assists, lt assists
[ ( "Joe", 0, 1, 1, 0, 0 )
, ( "Bob", 1, 0, 0, 1, 1 )
, ( "Steve", 2, 0, 0, 1, 1 )
, ( "Dave", 3, 0, 0, 0, 0 )
]
it "should clear the goalBy value" $
ps^.progMode.gameStateL.goalBy `shouldBe` ""
it "should clear the assistsBy list" $
ps^.progMode.gameStateL.assistsBy `shouldBe` []
it "should increment the pointsAccounted counter" $
ps^.progMode.gameStateL.pointsAccounted `shouldBe` 1
awardGoalSpec :: Spec awardGoalSpec :: Spec
awardGoalSpec = describe "awardGoal" $ do awardGoalSpec = describe "awardGoal" $ do
let let