update awardAssist

This commit is contained in:
Jonathan Lamothe
2019-10-03 02:28:16 -04:00
parent ad840cca65
commit 9d04abecff
2 changed files with 31 additions and 39 deletions

View File

@@ -193,13 +193,16 @@ awardAssist
-> ProgState -> ProgState
-> ProgState -> ProgState
awardAssist n ps = ps awardAssist n ps = ps
& database.dbPlayers & progMode.gameStateL.gamePlayerStats %~
%~ map (\m -> let
(\(i, p) -> if i == n stats = M.findWithDefault newPlayerStats n m
then p in M.insert n (stats & psAssists %~ succ) m)
& pYtd.psAssists %~ succ & database.dbPlayers %~ map
& pLifetime.psAssists %~ succ (\(i, p) -> if i == n
else p) . zip [0..] then p
& pYtd.psAssists %~ succ
& pLifetime.psAssists %~ succ
else p) . zip [0..]
-- | Resets the entered data for the current goal -- | Resets the entered data for the current goal
resetGoalData :: ProgState -> ProgState resetGoalData :: ProgState -> ProgState

View File

@@ -477,45 +477,34 @@ awardAssistSpec = describe "awardAssist" $ do
= newPlayer 2 "Bob" "defense" = newPlayer 2 "Bob" "defense"
& pYtd.psAssists .~ 3 & pYtd.psAssists .~ 3
& pLifetime.psAssists .~ 4 & pLifetime.psAssists .~ 4
joeStats
= newPlayerStats
& psAssists .~ 1
ps ps
= newProgState = newProgState
& progMode.gameStateL.gamePlayerStats .~ M.singleton 0 joeStats
& database.dbPlayers .~ [joe, bob] & database.dbPlayers .~ [joe, bob]
context "Joe" $ do mapM_
let (\(pName, pid, ytd, lt, game) ->
ps' = awardAssist 0 ps context pName $ do
joe' = head $ ps'^.database.dbPlayers let
bob' = last $ ps'^.database.dbPlayers ps' = awardAssist pid ps
player = (ps'^.database.dbPlayers) !! pid
gStats = (ps'^.progMode.gameStateL.gamePlayerStats) M.! pid
it "should increment Joe's year-to-date assists" $ it ("should increment " ++ pName ++ "'s year-to-date assists") $
joe'^.pYtd.psAssists `shouldBe` 2 player^.pYtd.psAssists `shouldBe` ytd
it "should increment Joe's lifetime assists" $ it ("should increment " ++ pName ++ "'s lifetime assists") $
joe'^.pLifetime.psAssists `shouldBe` 3 player^.pLifetime.psAssists `shouldBe` lt
it "should leave Bob's year-to-date assists alone" $ it ("should increment " ++ pName ++ "'s game assists") $
bob'^.pYtd.psAssists `shouldBe` 3 gStats^.psAssists `shouldBe` game)
-- player name, player id, ytd assists, lifetime assists, game assists
it "should leave Bob's lifetime assists alone" $ [ ( "Joe", 0, 2, 3, 2 )
bob^.pLifetime.psAssists `shouldBe` 4 , ( "Bob", 1, 4, 5, 1 )
]
context "Bob" $ do
let
ps' = awardAssist 1 ps
joe' = head $ ps'^.database.dbPlayers
bob' = last $ ps'^.database.dbPlayers
it "should leave Joe's year-to-date assists alone" $
joe'^.pYtd.psAssists `shouldBe` 1
it "should leave Joe's lifetime assists alone" $
joe'^.pLifetime.psAssists `shouldBe` 2
it "should increment Bob's year-to-date assists" $
bob'^.pYtd.psAssists `shouldBe` 4
it "should increment Bob's lifetime assists" $
bob'^.pLifetime.psAssists `shouldBe` 5
context "invalid index" $ let context "invalid index" $ let
ps' = awardAssist (-1) ps ps' = awardAssist (-1) ps