renamed/refactored teamPoints

- renamed to teamScore
This commit is contained in:
Jonathan Lamothe 2019-08-22 14:59:19 -04:00
parent ef7d34110a
commit 4d158a28db
2 changed files with 41 additions and 43 deletions

View File

@ -81,7 +81,7 @@ module Mtlstats.Types (
newGoalieStats, newGoalieStats,
-- * Helper Functions -- * Helper Functions
-- ** ProgState Helpers -- ** ProgState Helpers
teamPoints, teamScore,
-- ** Player Helpers -- ** Player Helpers
pPoints pPoints
) where ) where
@ -407,13 +407,11 @@ newGoalieStats = GoalieStats
} }
-- | Determines the team's points -- | Determines the team's points
teamPoints :: ProgState -> Maybe Int teamScore :: ProgState -> Maybe Int
teamPoints s = case s ^. progMode of teamScore s = case s ^. progMode . gameTypeL of
NewGame gs -> case gs ^. gameType of Just HomeGame -> s ^. progMode . homeScoreL
Just HomeGame -> gs ^. homeScore Just AwayGame -> s ^. progMode . awayScoreL
Just AwayGame -> gs ^. awayScore
Nothing -> Nothing Nothing -> Nothing
_ -> Nothing
-- | Calculates a player's points -- | Calculates a player's points
pPoints :: PlayerStats -> Int pPoints :: PlayerStats -> Int

View File

@ -34,16 +34,27 @@ import qualified Types.MenuSpec as Menu
spec :: Spec spec :: Spec
spec = describe "Mtlstats.Types" $ do spec = describe "Mtlstats.Types" $ do
pPointsSpec
teamPointsSpec
playerSpec playerSpec
pPointsSpec
goalieSpec goalieSpec
databaseSpec databaseSpec
gameTypeLSpec gameTypeLSpec
homeScoreLSpec homeScoreLSpec
awayScoreLSpec awayScoreLSpec
teamScoreSpec
Menu.spec Menu.spec
playerSpec :: Spec
playerSpec = describe "Player" $ do
describe "decode" $
it "should decode" $
decode playerJSON `shouldBe` Just player
describe "encode" $
it "should encode" $
decode (encode player) `shouldBe` Just player
pPointsSpec :: Spec pPointsSpec :: Spec
pPointsSpec = describe "pPoints" $ mapM_ pPointsSpec = describe "pPoints" $ mapM_
(\(goals, assists, points) -> let (\(goals, assists, points) -> let
@ -62,39 +73,6 @@ pPointsSpec = describe "pPoints" $ mapM_
, ( 2, 3, 5 ) , ( 2, 3, 5 )
] ]
teamPointsSpec :: Spec
teamPointsSpec = describe "teamPoints" $ do
let
m t = NewGame $ newGameState
& gameType ?~ t
& homeScore ?~ 1
& awayScore ?~ 2
s t = newProgState
& progMode .~ m t
context "unexpected state" $
it "should return Nothing" $
teamPoints newProgState `shouldBe` Nothing
context "HomeGame" $
it "should return 1" $
teamPoints (s HomeGame) `shouldBe` Just 1
context "AwayGame" $
it "should return 2" $
teamPoints (s AwayGame) `shouldBe` Just 2
playerSpec :: Spec
playerSpec = describe "Player" $ do
describe "decode" $
it "should decode" $
decode playerJSON `shouldBe` Just player
describe "encode" $
it "should encode" $
decode (encode player) `shouldBe` Just player
goalieSpec :: Spec goalieSpec :: Spec
goalieSpec = describe "Goalie" $ do goalieSpec = describe "Goalie" $ do
@ -205,6 +183,28 @@ awayScoreLSpec = describe "awayScoreL" $ do
m = NewGame newGameState & awayScoreL ?~ 0 m = NewGame newGameState & awayScoreL ?~ 0
in m ^. awayScoreL `shouldBe` Just 0 in m ^. awayScoreL `shouldBe` Just 0
teamScoreSpec :: Spec
teamScoreSpec = describe "teamScore" $ do
let
m t = NewGame $ newGameState
& gameType ?~ t
& homeScore ?~ 1
& awayScore ?~ 2
s t = newProgState
& progMode .~ m t
context "unexpected state" $
it "should return Nothing" $
teamScore newProgState `shouldBe` Nothing
context "HomeGame" $
it "should return 1" $
teamScore (s HomeGame) `shouldBe` Just 1
context "AwayGame" $
it "should return 2" $
teamScore (s AwayGame) `shouldBe` Just 2
player :: Player player :: Player
player = newPlayer 1 "Joe" "centre" player = newPlayer 1 "Joe" "centre"
& pYtd . psGoals .~ 2 & pYtd . psGoals .~ 2