recordGoalieStats should bump a goalie's game count only once per game

This commit is contained in:
Jonathan Lamothe 2019-11-01 17:23:57 -04:00
parent a63d822f02
commit 4fab3ec285
3 changed files with 62 additions and 44 deletions

View File

@ -285,7 +285,13 @@ recordGoalieStats s = fromMaybe s $ do
goals <- gs^.goalsAllowed goals <- gs^.goalsAllowed
let let
gameStats = M.findWithDefault newGoalieStats gid $ gs^.gameGoalieStats
bumpVal = if gameStats^.gsGames == 0
then 1
else 0
bumpStats gs = gs bumpStats gs = gs
& gsGames +~ bumpVal
& gsMinsPlayed +~ mins & gsMinsPlayed +~ mins
& gsGoalsAllowed +~ goals & gsGoalsAllowed +~ goals

View File

@ -680,20 +680,21 @@ assignPMinsSpec = describe "assignPMins" $ let
recordGoalieStatsSpec :: Spec recordGoalieStatsSpec :: Spec
recordGoalieStatsSpec = describe "recordGoalieStats" $ let recordGoalieStatsSpec = describe "recordGoalieStats" $ let
goalieStats mins goals = newGoalieStats goalieStats games mins goals = newGoalieStats
& gsGames .~ games
& gsMinsPlayed .~ mins & gsMinsPlayed .~ mins
& gsGoalsAllowed .~ goals & gsGoalsAllowed .~ goals
joe = newGoalie 2 "Joe" joe = newGoalie 2 "Joe"
& gYtd .~ goalieStats 10 11 & gYtd .~ goalieStats 10 11 12
& gLifetime .~ goalieStats 12 13 & gLifetime .~ goalieStats 20 21 22
bob = newGoalie 3 "Bob" bob = newGoalie 3 "Bob"
& gYtd .~ goalieStats 14 15 & gYtd .~ goalieStats 30 31 32
& gLifetime .~ goalieStats 16 17 & gLifetime .~ goalieStats 40 41 42
gameState n mins goals = newGameState gameState n mins goals = newGameState
& gameGoalieStats .~ M.fromList [(1, goalieStats 1 2)] & gameGoalieStats .~ M.fromList [(1, goalieStats 1 2 3)]
& gameSelectedGoalie .~ n & gameSelectedGoalie .~ n
& goalieMinsPlayed .~ mins & goalieMinsPlayed .~ mins
& goalsAllowed .~ goals & goalsAllowed .~ goals
@ -708,8 +709,19 @@ recordGoalieStatsSpec = describe "recordGoalieStats" $ let
in context name $ do in context name $ do
mapM_ mapM_
(\(name, gid, (gMins, gGoals, ytdMins, ytdGoals, ltMins, ltGoals)) -> (\( name
context name $ do , gid
, ( gGames
, gMins
, gGoals
, ytdGames
, ytdMins
, ytdGoals
, ltGames
, ltMins
, ltGoals
)
) -> context name $ do
let let
gs = s^.progMode.gameStateL.gameGoalieStats gs = s^.progMode.gameStateL.gameGoalieStats
game = M.findWithDefault newGoalieStats gid gs game = M.findWithDefault newGoalieStats gid gs
@ -717,31 +729,17 @@ recordGoalieStatsSpec = describe "recordGoalieStats" $ let
ytd = goalie^.gYtd ytd = goalie^.gYtd
lt = goalie^.gLifetime lt = goalie^.gLifetime
context "game minutes played" $ context "game" $
it ("should be " ++ show gMins) $ game `TS.compareTest` goalieStats gGames gMins gGoals
game^.gsMinsPlayed `shouldBe` gMins
context "game goals allowed" $ context "year-to-date" $
it ("should be " ++ show gGoals) $ ytd `TS.compareTest` goalieStats ytdGames ytdMins ytdGoals
game^.gsGoalsAllowed `shouldBe` gGoals
context "year-to-date minutes played" $ context "lifetime" $
it ("should be " ++ show ytdMins) $ lt `TS.compareTest` goalieStats ltGames ltMins ltGoals)
ytd^.gsMinsPlayed `shouldBe` ytdMins
context "year-to-date goals allowed" $ [ ( "checking Joe", 0, joeData )
it ("should be " ++ show ytdGoals) $ , ( "checking Bob", 1, bobData )
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 context "selected goalie" $ let
@ -759,52 +757,52 @@ recordGoalieStatsSpec = describe "recordGoalieStats" $ let
in it ("should be " ++ show expected) $ in it ("should be " ++ show expected) $
(s^.progMode.gameStateL.goalsAllowed) `shouldBe` expected) (s^.progMode.gameStateL.goalsAllowed) `shouldBe` expected)
[ ( "Joe" [ ( "updating Joe"
, Just 0 , Just 0
, Just 1 , Just 1
, Just 2 , Just 2
, ( 1, 2, 11, 13, 13, 15 ) , (1, 1, 2, 11, 12, 14, 21, 22, 24)
, ( 1, 2, 14, 15, 16, 17 ) , (1, 2, 3, 30, 31, 32, 40, 41, 42)
, True , True
) )
, ( "Bob" , ( "updating Bob"
, Just 1 , Just 1
, Just 1 , Just 1
, Just 2 , Just 2
, (0, 0, 10, 11, 12, 13 ) , (0, 0, 0, 10, 11, 12, 20, 21, 22)
, (2, 4, 15, 17, 17, 19 ) , (1, 3, 5, 30, 32, 34, 40, 42, 44)
, True , True
) )
, ( "goalie out of bounds" , ( "goalie out of bounds"
, Just 2 , Just 2
, Just 1 , Just 1
, Just 2 , Just 2
, (0, 0, 10, 11, 12, 13 ) , (0, 0, 0, 10, 11, 12, 20, 21, 22)
, (1, 2, 14, 15, 16, 17 ) , (1, 2, 3, 30, 31, 32, 40, 41, 42)
, False , False
) )
, ( "missing goalie" , ( "missing goalie"
, Nothing , Nothing
, Just 1 , Just 1
, Just 2 , Just 2
, (0, 0, 10, 11, 12, 13 ) , (0, 0, 0, 10, 11, 12, 20, 21, 22)
, (1, 2, 14, 15, 16, 17 ) , (1, 2, 3, 30, 31, 32, 40, 41, 42)
, False , False
) )
, ( "missing minutes" , ( "missing minutes"
, Just 0 , Just 0
, Nothing , Nothing
, Just 1 , Just 1
, (0, 0, 10, 11, 12, 13 ) , (0, 0, 0, 10, 11, 12, 20, 21, 22)
, (1, 2, 14, 15, 16, 17 ) , (1, 2, 3, 30, 31, 32, 40, 41, 42)
, False , False
) )
, ( "missing goals" , ( "missing goals"
, Just 0 , Just 0
, Just 1 , Just 1
, Nothing , Nothing
, (0, 0, 10, 11, 12, 13 ) , (0, 0, 0, 10, 11, 12, 20, 21, 22)
, (1, 2, 14, 15, 16, 17 ) , (1, 2, 3, 30, 31, 32, 40, 41, 42)
, False , False
) )
] ]

View File

@ -764,6 +764,20 @@ bob = newPlayer 3 "Bob" "defense"
steve :: Player steve :: Player
steve = newPlayer 5 "Steve" "forward" steve = newPlayer 5 "Steve" "forward"
instance Comparable GoalieStats where
compareTest actual expected = mapM_
(\(name, lens) -> describe name $
it ("should be " ++ show (expected^.lens)) $
actual^.lens `shouldBe` expected^.lens)
-- name, lens
[ ( "gsGames", gsGames )
, ( "gsMinsPlayed", gsMinsPlayed )
, ( "gsGoalsAllowed", gsGoalsAllowed )
, ( "gsWins", gsWins )
, ( "gsLosses", gsLosses )
, ( "gsTies", gsTies )
]
instance Comparable GameState where instance Comparable GameState where
compareTest actual expected = compareTest actual expected =
it ("should be " ++ show expected) $ it ("should be " ++ show expected) $