diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 517c39b..7e6b7f2 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -95,6 +95,7 @@ module Mtlstats.Types ( -- * Helper Functions -- ** GameState Helpers teamScore, + otherScore, -- ** Player Helpers pPoints ) where @@ -511,6 +512,13 @@ teamScore s = case s ^. gameType of Just AwayGame -> s ^. awayScore Nothing -> Nothing +-- | Determines the other team's score +otherScore :: GameState -> Maybe Int +otherScore s = case s ^. gameType of + Just HomeGame -> s ^. awayScore + Just AwayGame -> s ^. homeScore + 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 60f7918..b67983a 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -46,6 +46,7 @@ spec = describe "Mtlstats.Types" $ do homeScoreLSpec awayScoreLSpec teamScoreSpec + otherScoreSpec Menu.spec playerSpec :: Spec @@ -214,6 +215,26 @@ teamScoreSpec = describe "teamScore" $ do it "should return 2" $ teamScore (s AwayGame) `shouldBe` Just 2 +otherScoreSpec :: Spec +otherScoreSpec = describe "otherScore" $ do + let + s t = newGameState + & gameType ?~ t + & homeScore ?~ 1 + & awayScore ?~ 2 + + context "unknown game type" $ + it "should return Nothing" $ + otherScore newGameState `shouldBe` Nothing + + context "HomeGame" $ + it "should return 2" $ + otherScore (s HomeGame) `shouldBe` Just 2 + + context "AwayGame" $ + it "should return 1" $ + otherScore (s AwayGame) `shouldBe` Just 1 + jsonSpec :: (Eq a, Show a, FromJSON a, ToJSON a) => a