diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 374be7d..e864b4e 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -75,7 +75,10 @@ module Mtlstats.Types ( newPlayerStats, newGoalie, newGoalieStats, - -- * Helper functions + -- * Helper Functions + -- ** ProgState Helpers + teamPoints, + -- ** Player Helpers pPoints ) where @@ -372,6 +375,15 @@ newGoalieStats = GoalieStats , _gsTies = 0 } +-- | 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 ^. visitorScore + Nothing -> Nothing + _ -> Nothing + -- | Calculates a player's points pPoints :: PlayerStats -> Int pPoints s = s^.psGoals + s^.psAssists diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 085dac4..c33ea2d 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -35,6 +35,7 @@ import qualified Types.MenuSpec as Menu spec :: Spec spec = describe "Mtlstats.Types" $ do pPointsSpec + teamPointsSpec playerSpec goalieSpec databaseSpec @@ -58,6 +59,28 @@ pPointsSpec = describe "pPoints" $ mapM_ , ( 2, 3, 5 ) ] +teamPointsSpec :: Spec +teamPointsSpec = describe "teamPoints" $ do + let + m t = NewGame $ newGameState + & gameType .~ Just t + & homeScore .~ Just 1 + & visitorScore .~ Just 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