From e6e28618a3561cddd484fe5cfe2b9b7ac1d81bfa Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 14 Nov 2019 11:21:52 -0500 Subject: [PATCH] reset game standings on new season --- src/Mtlstats/Actions.hs | 7 +++++++ src/Mtlstats/Menu.hs | 12 +++++++----- test/ActionsSpec.hs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/Mtlstats/Actions.hs b/src/Mtlstats/Actions.hs index 698ac0b..fc03ec1 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 + , resetStandings , startNewGame , addChar , removeChar @@ -56,6 +57,12 @@ resetYtd = (database . dbPlayers %~ map (pYtd .~ newPlayerStats)) . (database . dbGoalies %~ map (gYtd .~ newGoalieStats)) +-- | Resets game standings +resetStandings :: ProgState -> ProgState +resetStandings = database + %~ ( dbHomeGameStats .~ newGameStats) + . ( dbAwayGameStats .~ newGameStats) + -- | Starts a new game startNewGame :: ProgState -> ProgState startNewGame diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index b2c04e1..51c5029 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -119,11 +119,13 @@ mainMenu = Menu "*** MAIN MENU ***" True -- | The new season menu newSeasonMenu :: Menu () newSeasonMenu = Menu "*** SEASON TYPE ***" () - [ MenuItem '1' "Regular Season" $ do - modify resetYtd - modify startNewGame - , MenuItem '2' "Playoffs" $ - modify startNewGame + [ MenuItem '1' "Regular Season" $ modify + $ resetYtd + . resetStandings + . startNewGame + , MenuItem '2' "Playoffs" $ modify + $ resetStandings + . startNewGame ] -- | Requests the month in which the game took place diff --git a/test/ActionsSpec.hs b/test/ActionsSpec.hs index 19a16f3..8f6b764 100644 --- a/test/ActionsSpec.hs +++ b/test/ActionsSpec.hs @@ -47,6 +47,7 @@ spec = describe "Mtlstats.Actions" $ do startNewSeasonSpec startNewGameSpec resetYtdSpec + resetStandingsSpec addCharSpec removeCharSpec createPlayerSpec @@ -127,6 +128,41 @@ resetYtdSpec = describe "resetYtd" $ lt ^. gsTies `shouldNotBe` 0) $ s ^. database . dbGoalies +resetStandingsSpec :: Spec +resetStandingsSpec = describe "resetStandings" $ do + let + home = GameStats + { _gmsWins = 1 + , _gmsLosses = 2 + , _gmsOvertime = 3 + , _gmsGoalsFor = 4 + , _gmsGoalsAgainst = 5 + } + + away = GameStats + { _gmsWins = 6 + , _gmsLosses = 7 + , _gmsOvertime = 8 + , _gmsGoalsFor = 9 + , _gmsGoalsAgainst = 10 + } + + db = newDatabase + & dbHomeGameStats .~ home + & dbAwayGameStats .~ away + + ps = newProgState + & database .~ db + & resetStandings + + context "home standings" $ + it "should be reset" $ + ps^.database.dbHomeGameStats `shouldBe` newGameStats + + context "away standings" $ + it "should be reset" $ + ps^.database.dbAwayGameStats `shouldBe` newGameStats + addCharSpec :: Spec addCharSpec = describe "addChar" $ it "should add the character to the input buffer" $ let