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

View File

@ -34,16 +34,27 @@ import qualified Types.MenuSpec as Menu
spec :: Spec
spec = describe "Mtlstats.Types" $ do
pPointsSpec
teamPointsSpec
playerSpec
pPointsSpec
goalieSpec
databaseSpec
gameTypeLSpec
homeScoreLSpec
awayScoreLSpec
teamScoreSpec
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 = describe "pPoints" $ mapM_
(\(goals, assists, points) -> let
@ -62,39 +73,6 @@ pPointsSpec = describe "pPoints" $ mapM_
, ( 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 = describe "Goalie" $ do
@ -205,6 +183,28 @@ awayScoreLSpec = describe "awayScoreL" $ do
m = NewGame newGameState & awayScoreL ?~ 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 = newPlayer 1 "Joe" "centre"
& pYtd . psGoals .~ 2