From 3b4ce50ae81b9259122eae8291fd1319a397dfc0 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 11 Jan 2020 02:29:17 -0500 Subject: [PATCH] clear rookies on new (regular) season --- ChangeLog.md | 1 + src/Mtlstats/Actions.hs | 7 +++++++ src/Mtlstats/Menu.hs | 1 + test/ActionsSpec.hs | 42 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 6fb81a6..3aeaf7a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ ## current - Added active flag to players/goalies +- Clear rookie flag on new (regular) season ## 0.10.0 - Don't show player number zero in reports diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 73767a0..e255301 100644 --- a/src/Mtlstats/Actions.hs +++ b/src/Mtlstats/Actions.hs @@ -24,6 +24,7 @@ along with this program. If not, see . module Mtlstats.Actions ( startNewSeason , resetYtd + , clearRookies , resetStandings , startNewGame , addChar @@ -61,6 +62,12 @@ resetYtd = (database . dbPlayers %~ map (pYtd .~ newPlayerStats)) . (database . dbGoalies %~ map (gYtd .~ newGoalieStats)) +-- | Clears the rookie flag from all players/goalies +clearRookies :: ProgState -> ProgState +clearRookies = database + %~ (dbPlayers %~ map (pRookie .~ False)) + . (dbGoalies %~ map (gRookie .~ False)) + -- | Resets game standings resetStandings :: ProgState -> ProgState resetStandings = database diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 5a4f511..40d49a0 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -131,6 +131,7 @@ newSeasonMenu :: Menu () newSeasonMenu = Menu "*** SEASON TYPE ***" () [ MenuItem 'R' "Regular Season" $ modify $ resetYtd + . clearRookies . resetStandings . startNewGame , MenuItem 'P' "Playoffs" $ modify diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 0bfb02c..24ab67a 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -24,7 +24,7 @@ along with this program. If not, see . module ActionsSpec (spec) where import Control.Monad (replicateM) -import Lens.Micro ((^.), (&), (.~), (?~)) +import Lens.Micro ((^.), (&), (.~), (?~), (%~)) import Test.Hspec ( Spec , context @@ -46,6 +46,7 @@ spec = describe "Mtlstats.Actions" $ do startNewSeasonSpec startNewGameSpec resetYtdSpec + clearRookiesSpec resetStandingsSpec addCharSpec removeCharSpec @@ -129,6 +130,45 @@ resetYtdSpec = describe "resetYtd" $ lt ^. gsTies `shouldNotBe` 0) $ s ^. database . dbGoalies +clearRookiesSpec :: Spec +clearRookiesSpec = describe "clearRookies" $ do + let + + players = + [ newPlayer 1 "Joe" "centre" & pRookie .~ True + , newPlayer 2 "Bob" "centre" & pRookie .~ False + ] + + goalies = + [ newGoalie 3 "Bill" & gRookie .~ True + , newGoalie 4 "Doug" & gRookie .~ False + ] + + ps = newProgState + & database + %~ (dbPlayers .~ players) + . (dbGoalies .~ goalies) + + ps' = clearRookies ps + + context "Players" $ mapM_ + (\p -> let + name = p^.pName + rFlag = p^.pRookie + in context name $ + it "should not be a rookie" $ + rFlag `shouldBe` False) + (ps'^.database.dbPlayers) + + context "Goalies" $ mapM_ + (\g -> let + name = g^.gName + rFlag = g^.gRookie + in context name $ + it "should not be a rookie" $ + rFlag `shouldBe` False) + (ps'^.database.dbGoalies) + resetStandingsSpec :: Spec resetStandingsSpec = describe "resetStandings" $ do let