implemented recordGoalieStats

This commit is contained in:
Jonathan Lamothe 2019-10-31 03:21:11 -04:00
parent ff541c2385
commit eb96ce6152
2 changed files with 154 additions and 1 deletions

View File

@ -272,7 +272,28 @@ assignPMins mins s = fromMaybe s $ do
-- | Records the goalie's game stats
recordGoalieStats :: ProgState -> ProgState
recordGoalieStats = undefined
recordGoalieStats s = fromMaybe s $ do
let gs = s^.progMode.gameStateL
gid <- gs^.gameSelectedGoalie
goalie <- nth gid $ s^.database.dbGoalies
mins <- gs^.goalieMinsPlayed
goals <- gs^.goalsAllowed
let
bumpStats gs = gs
& gsMinsPlayed +~ mins
& gsGoalsAllowed +~ goals
Just $ s
& progMode.gameStateL
%~ (gameGoalieStats %~ updateMap gid newGoalieStats bumpStats)
. (gameSelectedGoalie .~ Nothing)
. (goalieMinsPlayed .~ Nothing)
. (goalsAllowed .~ Nothing)
& database.dbGoalies
%~ modifyNth gid (\goalie -> goalie
& gYtd %~ bumpStats
& gLifetime %~ bumpStats)
-- | Resets the program state back to the main menu
backHome :: ProgState -> ProgState

View File

@ -66,6 +66,7 @@ spec = describe "Mtlstats.Actions" $ do
awardAssistSpec
resetGoalDataSpec
assignPMinsSpec
recordGoalieStatsSpec
backHomeSpec
scrollUpSpec
scrollDownSpec
@ -670,6 +671,137 @@ assignPMinsSpec = describe "assignPMins" $ let
, ( Nothing, 4, 3, 2, 6, 5, 0 )
]
recordGoalieStatsSpec :: Spec
recordGoalieStatsSpec = describe "recordGoalieStats" $ let
goalieStats mins goals = newGoalieStats
& gsMinsPlayed .~ mins
& gsGoalsAllowed .~ goals
joe = newGoalie 2 "Joe"
& gYtd .~ goalieStats 10 11
& gLifetime .~ goalieStats 12 13
bob = newGoalie 3 "Bob"
& gYtd .~ goalieStats 14 15
& gLifetime .~ goalieStats 16 17
gameState n mins goals = newGameState
& gameGoalieStats .~ M.fromList [(1, goalieStats 1 2)]
& gameSelectedGoalie .~ n
& goalieMinsPlayed .~ mins
& goalsAllowed .~ goals
progState n mins goals = newProgState
& database.dbGoalies .~ [joe, bob]
& progMode.gameStateL .~ gameState n mins goals
in mapM_
(\(name, gid, mins, goals, joeData, bobData, reset) -> let
s = recordGoalieStats $ progState gid mins goals
in context name $ do
mapM_
(\(name, gid, (gMins, gGoals, ytdMins, ytdGoals, ltMins, ltGoals)) ->
context name $ do
let
gs = s^.progMode.gameStateL.gameGoalieStats
game = M.findWithDefault newGoalieStats gid gs
goalie = fromJust $ nth gid $ s^.database.dbGoalies
ytd = goalie^.gYtd
lt = goalie^.gLifetime
context "game minutes played" $
it ("should be " ++ show gMins) $
game^.gsMinsPlayed `shouldBe` gMins
context "game goals allowed" $
it ("should be " ++ show gGoals) $
game^.gsGoalsAllowed `shouldBe` gGoals
context "year-to-date minutes played" $
it ("should be " ++ show ytdMins) $
ytd^.gsMinsPlayed `shouldBe` ytdMins
context "year-to-date goals allowed" $
it ("should be " ++ show ytdGoals) $
ytd^.gsGoalsAllowed `shouldBe` ytdGoals
context "lifetime minutes played" $
it ("should be " ++ show ltMins) $
lt^.gsMinsPlayed `shouldBe` ltMins
context "lifetime goals allowed" $
it ("should be " ++ show ltGoals) $
lt^.gsGoalsAllowed `shouldBe` ltGoals)
[ ( "Joe", 0, joeData )
, ( "Bob", 1, bobData )
]
context "selected goalie" $ let
expected = if reset then Nothing else gid
in it ("should be " ++ show expected) $
(s^.progMode.gameStateL.gameSelectedGoalie) `shouldBe` expected
context "minutes played" $ let
expected = if reset then Nothing else mins
in it ("should be " ++ show expected) $
(s^.progMode.gameStateL.goalieMinsPlayed) `shouldBe` expected
context "goals allowed" $ let
expected = if reset then Nothing else goals
in it ("should be " ++ show expected) $
(s^.progMode.gameStateL.goalsAllowed) `shouldBe` expected)
[ ( "Joe"
, Just 0
, Just 1
, Just 2
, ( 1, 2, 11, 13, 13, 15 )
, ( 1, 2, 14, 15, 16, 17 )
, True
)
, ( "Bob"
, Just 1
, Just 1
, Just 2
, (0, 0, 10, 11, 12, 13 )
, (2, 4, 15, 17, 17, 19 )
, True
)
, ( "goalie out of bounds"
, Just 2
, Just 1
, Just 2
, (0, 0, 10, 11, 12, 13 )
, (1, 2, 14, 15, 16, 17 )
, False
)
, ( "missing goalie"
, Nothing
, Just 1
, Just 2
, (0, 0, 10, 11, 12, 13 )
, (1, 2, 14, 15, 16, 17 )
, False
)
, ( "missing minutes"
, Just 0
, Nothing
, Just 1
, (0, 0, 10, 11, 12, 13 )
, (1, 2, 14, 15, 16, 17 )
, False
)
, ( "missing goals"
, Just 0
, Just 1
, Nothing
, (0, 0, 10, 11, 12, 13 )
, (1, 2, 14, 15, 16, 17 )
, False
)
]
makePlayer :: IO Player
makePlayer = Player
<$> makeNum