Merge pull request #37 from mtlstats/reset-standings

reset game standings on new season
This commit is contained in:
Jonathan Lamothe 2019-11-14 11:35:26 -05:00 committed by GitHub
commit 7824d56d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 5 deletions

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Actions module Mtlstats.Actions
( startNewSeason ( startNewSeason
, resetYtd , resetYtd
, resetStandings
, startNewGame , startNewGame
, addChar , addChar
, removeChar , removeChar
@ -56,6 +57,12 @@ resetYtd
= (database . dbPlayers %~ map (pYtd .~ newPlayerStats)) = (database . dbPlayers %~ map (pYtd .~ newPlayerStats))
. (database . dbGoalies %~ map (gYtd .~ newGoalieStats)) . (database . dbGoalies %~ map (gYtd .~ newGoalieStats))
-- | Resets game standings
resetStandings :: ProgState -> ProgState
resetStandings = database
%~ ( dbHomeGameStats .~ newGameStats)
. ( dbAwayGameStats .~ newGameStats)
-- | Starts a new game -- | Starts a new game
startNewGame :: ProgState -> ProgState startNewGame :: ProgState -> ProgState
startNewGame startNewGame

View File

@ -119,11 +119,13 @@ mainMenu = Menu "*** MAIN MENU ***" True
-- | The new season menu -- | The new season menu
newSeasonMenu :: Menu () newSeasonMenu :: Menu ()
newSeasonMenu = Menu "*** SEASON TYPE ***" () newSeasonMenu = Menu "*** SEASON TYPE ***" ()
[ MenuItem '1' "Regular Season" $ do [ MenuItem '1' "Regular Season" $ modify
modify resetYtd $ resetYtd
modify startNewGame . resetStandings
, MenuItem '2' "Playoffs" $ . startNewGame
modify startNewGame , MenuItem '2' "Playoffs" $ modify
$ resetStandings
. startNewGame
] ]
-- | Requests the month in which the game took place -- | Requests the month in which the game took place

View File

@ -47,6 +47,7 @@ spec = describe "Mtlstats.Actions" $ do
startNewSeasonSpec startNewSeasonSpec
startNewGameSpec startNewGameSpec
resetYtdSpec resetYtdSpec
resetStandingsSpec
addCharSpec addCharSpec
removeCharSpec removeCharSpec
createPlayerSpec createPlayerSpec
@ -127,6 +128,41 @@ resetYtdSpec = describe "resetYtd" $
lt ^. gsTies `shouldNotBe` 0) $ lt ^. gsTies `shouldNotBe` 0) $
s ^. database . dbGoalies 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 :: Spec
addCharSpec = describe "addChar" $ addCharSpec = describe "addChar" $
it "should add the character to the input buffer" $ let it "should add the character to the input buffer" $ let