implemented otherScore
This commit is contained in:
parent
29459063c8
commit
97a42fd1de
|
@ -95,6 +95,7 @@ module Mtlstats.Types (
|
||||||
-- * Helper Functions
|
-- * Helper Functions
|
||||||
-- ** GameState Helpers
|
-- ** GameState Helpers
|
||||||
teamScore,
|
teamScore,
|
||||||
|
otherScore,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
pPoints
|
pPoints
|
||||||
) where
|
) where
|
||||||
|
@ -511,6 +512,13 @@ teamScore s = case s ^. gameType of
|
||||||
Just AwayGame -> s ^. awayScore
|
Just AwayGame -> s ^. awayScore
|
||||||
Nothing -> Nothing
|
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
|
-- | Calculates a player's points
|
||||||
pPoints :: PlayerStats -> Int
|
pPoints :: PlayerStats -> Int
|
||||||
pPoints s = s^.psGoals + s^.psAssists
|
pPoints s = s^.psGoals + s^.psAssists
|
||||||
|
|
|
@ -46,6 +46,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||||
homeScoreLSpec
|
homeScoreLSpec
|
||||||
awayScoreLSpec
|
awayScoreLSpec
|
||||||
teamScoreSpec
|
teamScoreSpec
|
||||||
|
otherScoreSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
|
||||||
playerSpec :: Spec
|
playerSpec :: Spec
|
||||||
|
@ -214,6 +215,26 @@ teamScoreSpec = describe "teamScore" $ do
|
||||||
it "should return 2" $
|
it "should return 2" $
|
||||||
teamScore (s AwayGame) `shouldBe` Just 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
|
jsonSpec
|
||||||
:: (Eq a, Show a, FromJSON a, ToJSON a)
|
:: (Eq a, Show a, FromJSON a, ToJSON a)
|
||||||
=> a
|
=> a
|
||||||
|
|
Loading…
Reference in New Issue
Block a user