implemented otherScore
This commit is contained in:
parent
29459063c8
commit
97a42fd1de
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user