implemented resetYtd
This commit is contained in:
parent
943efe0599
commit
51e591861d
|
@ -25,6 +25,7 @@ dependencies:
|
|||
- extra >= 1.6.17 && < 1.7
|
||||
- microlens-th >= 0.4.2.3 && < 0.5
|
||||
- ncurses >= 0.2.16 && < 0.3
|
||||
- random >= 1.1 && < 1.2
|
||||
- raw-strings-qq >= 1.1 && < 1.2
|
||||
- transformers >= 0.5.6.2 && < 0.6
|
||||
- bytestring
|
||||
|
|
|
@ -25,7 +25,7 @@ module Mtlstats.Actions
|
|||
, startNewGame
|
||||
) where
|
||||
|
||||
import Lens.Micro ((.~))
|
||||
import Lens.Micro ((.~), (%~))
|
||||
|
||||
import Mtlstats.Types
|
||||
|
||||
|
@ -35,7 +35,9 @@ startNewSeason = (progMode .~ NewSeason) . (database . dbGames .~ 0)
|
|||
|
||||
-- | Resets all players year-to-date stats
|
||||
resetYtd :: ProgState -> ProgState
|
||||
resetYtd = undefined
|
||||
resetYtd
|
||||
= (database . dbPlayers %~ map (pYtd .~ newPlayerStats))
|
||||
. (database . dbGoalies %~ map (gYtd .~ newGoalieStats))
|
||||
|
||||
-- | Starts a new game
|
||||
startNewGame :: ProgState -> ProgState
|
||||
|
|
|
@ -21,8 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
module ActionsSpec (spec) where
|
||||
|
||||
import Control.Monad (replicateM)
|
||||
import Lens.Micro ((&), (.~), (^.))
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
import System.Random (randomRIO)
|
||||
import Test.Hspec (Spec, describe, it, shouldBe, shouldNotBe)
|
||||
|
||||
import Mtlstats.Actions
|
||||
import Mtlstats.Types
|
||||
|
@ -31,6 +33,7 @@ spec :: Spec
|
|||
spec = describe "Mtlstats.Actions" $ do
|
||||
startNewSeasonSpec
|
||||
startNewGameSpec
|
||||
resetYtdSpec
|
||||
|
||||
startNewSeasonSpec :: Spec
|
||||
startNewSeasonSpec = describe "startNewSeason" $ do
|
||||
|
@ -47,3 +50,83 @@ startNewSeasonSpec = describe "startNewSeason" $ do
|
|||
|
||||
startNewGameSpec :: Spec
|
||||
startNewGameSpec = describe "startGame" $ return ()
|
||||
|
||||
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
|
||||
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user