changed teamScore to check GameState

This commit is contained in:
Jonathan Lamothe 2019-08-27 11:44:45 -04:00
parent 13d422100b
commit 29459063c8
2 changed files with 9 additions and 11 deletions

View File

@ -93,7 +93,7 @@ module Mtlstats.Types (
newGoalieStats, newGoalieStats,
newGameStats, newGameStats,
-- * Helper Functions -- * Helper Functions
-- ** ProgState Helpers -- ** GameState Helpers
teamScore, teamScore,
-- ** Player Helpers -- ** Player Helpers
pPoints pPoints
@ -504,11 +504,11 @@ newGameStats = GameStats
, _gmsOvertime = 0 , _gmsOvertime = 0
} }
-- | Determines the team's points -- | Determines the team's score
teamScore :: ProgState -> Maybe Int teamScore :: GameState -> Maybe Int
teamScore s = case s ^. progMode . gameTypeL of teamScore s = case s ^. gameType of
Just HomeGame -> s ^. progMode . homeScoreL Just HomeGame -> s ^. homeScore
Just AwayGame -> s ^. progMode . awayScoreL Just AwayGame -> s ^. awayScore
Nothing -> Nothing Nothing -> Nothing
-- | Calculates a player's points -- | Calculates a player's points

View File

@ -197,16 +197,14 @@ awayScoreLSpec = describe "awayScoreL" $ do
teamScoreSpec :: Spec teamScoreSpec :: Spec
teamScoreSpec = describe "teamScore" $ do teamScoreSpec = describe "teamScore" $ do
let let
m t = NewGame $ newGameState s t = newGameState
& gameType ?~ t & gameType ?~ t
& homeScore ?~ 1 & homeScore ?~ 1
& awayScore ?~ 2 & awayScore ?~ 2
s t = newProgState
& progMode .~ m t
context "unexpected state" $ context "unknown game type" $
it "should return Nothing" $ it "should return Nothing" $
teamScore newProgState `shouldBe` Nothing teamScore newGameState `shouldBe` Nothing
context "HomeGame" $ context "HomeGame" $
it "should return 1" $ it "should return 1" $