2019-08-20 11:31:03 -04:00
|
|
|
{-
|
|
|
|
|
|
|
|
mtlstats
|
|
|
|
Copyright (C) 2019 Rhéal Lamothe
|
|
|
|
<rheal.lamothe@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
|
|
your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module ActionsSpec (spec) where
|
|
|
|
|
2019-08-21 15:57:52 -04:00
|
|
|
import Control.Monad (replicateM)
|
2019-08-22 10:25:23 -04:00
|
|
|
import Lens.Micro ((&), (.~), (?~), (^.))
|
2019-08-21 15:57:52 -04:00
|
|
|
import System.Random (randomRIO)
|
2019-08-22 02:37:47 -04:00
|
|
|
import Test.Hspec (Spec, context, describe, it, shouldBe, shouldNotBe)
|
2019-08-20 12:26:24 -04:00
|
|
|
|
|
|
|
import Mtlstats.Actions
|
|
|
|
import Mtlstats.Types
|
2019-08-20 11:31:03 -04:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = describe "Mtlstats.Actions" $ do
|
2019-08-20 12:26:24 -04:00
|
|
|
startNewSeasonSpec
|
|
|
|
startNewGameSpec
|
2019-08-21 15:57:52 -04:00
|
|
|
resetYtdSpec
|
2019-08-22 02:37:47 -04:00
|
|
|
setHomeGameSpec
|
|
|
|
setAwayGameSpec
|
2019-08-20 12:26:24 -04:00
|
|
|
|
|
|
|
startNewSeasonSpec :: Spec
|
|
|
|
startNewSeasonSpec = describe "startNewSeason" $ do
|
|
|
|
let
|
|
|
|
s = newProgState
|
|
|
|
& database . dbGames .~ 1
|
|
|
|
& startNewSeason
|
|
|
|
|
|
|
|
it "should set the progState to NewSeason" $
|
|
|
|
s ^. progMode `shouldBe` NewSeason
|
2019-08-20 11:31:03 -04:00
|
|
|
|
2019-08-20 12:26:24 -04:00
|
|
|
it "should set the number of games to 0" $
|
|
|
|
s ^. database . dbGames `shouldBe` 0
|
2019-08-20 11:31:03 -04:00
|
|
|
|
2019-08-20 12:26:24 -04:00
|
|
|
startNewGameSpec :: Spec
|
2019-08-22 01:18:02 -04:00
|
|
|
startNewGameSpec = describe "startNewGame" $ do
|
|
|
|
let
|
|
|
|
s = newProgState
|
|
|
|
& database . dbGames .~ 1
|
|
|
|
& startNewGame
|
|
|
|
|
|
|
|
it "should set the number of games to 0" $
|
|
|
|
s ^. database . dbGames `shouldBe` 0
|
|
|
|
|
|
|
|
it "should set the mode to NewGame" $
|
|
|
|
s ^. progMode `shouldBe` NewGame newGameState
|
2019-08-21 15:57:52 -04:00
|
|
|
|
|
|
|
resetYtdSpec :: Spec
|
|
|
|
resetYtdSpec = describe "resetYtd" $
|
|
|
|
it "should reset the year-to-date stats for all players" $ do
|
|
|
|
ps <- replicateM 2 makePlayer
|
|
|
|
gs <- replicateM 2 makeGoalie
|
|
|
|
let
|
|
|
|
s = newProgState
|
|
|
|
& database . dbPlayers .~ ps
|
|
|
|
& database . dbGoalies .~ gs
|
|
|
|
& resetYtd
|
|
|
|
mapM_
|
|
|
|
(\p -> do
|
|
|
|
let
|
|
|
|
ytd = p ^. pYtd
|
|
|
|
lt = p ^. pLifetime
|
|
|
|
ytd ^. psGoals `shouldBe` 0
|
|
|
|
ytd ^. psAssists `shouldBe` 0
|
|
|
|
ytd ^. psPMin `shouldBe` 0
|
|
|
|
lt ^. psGoals `shouldNotBe` 0
|
|
|
|
lt ^. psAssists `shouldNotBe` 0
|
|
|
|
lt ^. psPMin `shouldNotBe` 0) $
|
|
|
|
s ^. database . dbPlayers
|
|
|
|
mapM_
|
|
|
|
(\g -> do
|
|
|
|
let
|
|
|
|
ytd = g ^. gYtd
|
|
|
|
lt = g ^. gLifetime
|
|
|
|
ytd ^. gsGames `shouldBe` 0
|
|
|
|
ytd ^. gsMinsPlayed `shouldBe` 0
|
|
|
|
ytd ^. gsGoalsAllowed `shouldBe` 0
|
|
|
|
ytd ^. gsGoalsAgainst `shouldBe` 0
|
|
|
|
ytd ^. gsWins `shouldBe` 0
|
|
|
|
ytd ^. gsLosses `shouldBe` 0
|
|
|
|
ytd ^. gsTies `shouldBe` 0
|
|
|
|
lt ^. gsGames `shouldNotBe` 0
|
|
|
|
lt ^. gsMinsPlayed `shouldNotBe` 0
|
|
|
|
lt ^. gsGoalsAllowed `shouldNotBe` 0
|
|
|
|
lt ^. gsGoalsAgainst `shouldNotBe` 0
|
|
|
|
lt ^. gsWins `shouldNotBe` 0
|
|
|
|
lt ^. gsLosses `shouldNotBe` 0
|
|
|
|
lt ^. gsTies `shouldNotBe` 0) $
|
|
|
|
s ^. database . dbGoalies
|
|
|
|
|
2019-08-22 02:37:47 -04:00
|
|
|
setHomeGameSpec :: Spec
|
|
|
|
setHomeGameSpec = describe "setHomeGame" $ do
|
2019-08-22 10:25:23 -04:00
|
|
|
let m = NewGame $ newGameState & gameType ?~ HomeGame
|
2019-08-22 02:37:47 -04:00
|
|
|
|
|
|
|
context "unexpected mode" $
|
|
|
|
it "should set the game type" $ let
|
|
|
|
s = setHomeGame newProgState
|
|
|
|
in s ^. progMode `shouldBe` m
|
|
|
|
|
|
|
|
context "NewGame mode" $
|
|
|
|
it "should set the game type" $ let
|
|
|
|
s = newProgState
|
|
|
|
& progMode .~ NewGame newGameState
|
|
|
|
& setHomeGame
|
|
|
|
in s ^. progMode `shouldBe` m
|
|
|
|
|
|
|
|
setAwayGameSpec :: Spec
|
|
|
|
setAwayGameSpec = describe "setAwayGame" $ do
|
2019-08-22 10:25:23 -04:00
|
|
|
let m = NewGame $ newGameState & gameType ?~ AwayGame
|
2019-08-22 02:37:47 -04:00
|
|
|
|
|
|
|
context "unexpected mode" $
|
|
|
|
it "should set the game type" $ let
|
|
|
|
s = setAwayGame newProgState
|
|
|
|
in s ^. progMode `shouldBe` m
|
|
|
|
|
|
|
|
context "NewGame mode" $
|
|
|
|
it "should set the game type" $ let
|
|
|
|
s = newProgState
|
|
|
|
& progMode .~ NewGame newGameState
|
|
|
|
& setAwayGame
|
|
|
|
in s ^. progMode `shouldBe` m
|
|
|
|
|
2019-08-21 15:57:52 -04:00
|
|
|
makePlayer :: IO Player
|
|
|
|
makePlayer = Player
|
|
|
|
<$> makeNum
|
|
|
|
<*> makeName
|
|
|
|
<*> makeName
|
|
|
|
<*> makePlayerStats
|
|
|
|
<*> makePlayerStats
|
|
|
|
|
|
|
|
makeGoalie :: IO Goalie
|
|
|
|
makeGoalie = Goalie
|
|
|
|
<$> makeNum
|
|
|
|
<*> makeName
|
|
|
|
<*> makeGoalieStats
|
|
|
|
<*> makeGoalieStats
|
|
|
|
|
|
|
|
makePlayerStats :: IO PlayerStats
|
|
|
|
makePlayerStats = PlayerStats
|
|
|
|
<$> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
|
|
|
|
makeGoalieStats :: IO GoalieStats
|
|
|
|
makeGoalieStats = GoalieStats
|
|
|
|
<$> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
<*> makeNum
|
|
|
|
|
|
|
|
makeNum :: IO Int
|
|
|
|
makeNum = randomRIO (1, 10)
|
|
|
|
|
|
|
|
makeName :: IO String
|
|
|
|
makeName = replicateM 10 $ randomRIO ('A', 'Z')
|