implemented addGameStats

This commit is contained in:
Jonathan Lamothe 2019-08-31 09:33:26 -04:00
parent 9e855d9672
commit f9e7710122
2 changed files with 34 additions and 0 deletions

View File

@ -99,6 +99,7 @@ module Mtlstats.Types (
gameTied,
-- ** GameStats Helpers
gmsPoints,
addGameStats,
-- ** Player Helpers
pPoints
) where
@ -512,6 +513,14 @@ gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
gmsPoints :: GameStats -> Int
gmsPoints gs = 2 * gs^.gmsWins + gs^. gmsOvertime
-- | Adds two 'GameStats' values together
addGameStats :: GameStats -> GameStats -> GameStats
addGameStats s1 s2 = GameStats
{ _gmsWins = s1^.gmsWins + s2^.gmsWins
, _gmsLosses = s1^.gmsLosses + s2^.gmsLosses
, _gmsOvertime = s1^.gmsOvertime + s2^.gmsOvertime
}
-- | Calculates a player's points
pPoints :: PlayerStats -> Int
pPoints s = s^.psGoals + s^.psAssists

View File

@ -47,6 +47,7 @@ spec = describe "Mtlstats.Types" $ do
gameLostSpec
gameTiedSpec
gmsPointsSpec
addGameStatsSpec
pPointsSpec
Menu.spec
@ -341,6 +342,30 @@ gmsPointsSpec = describe "gmsPoints" $ mapM_
, ( 2, 4, 3, 7 )
]
addGameStatsSpec :: Spec
addGameStatsSpec = describe "addGameStats" $
it "should add the values" $ let
s1 = GameStats
{ _gmsWins = 1
, _gmsLosses = 3
, _gmsOvertime = 2
}
s2 = GameStats
{ _gmsWins = 4
, _gmsLosses = 6
, _gmsOvertime = 5
}
expected = GameStats
{ _gmsWins = 5
, _gmsLosses = 9
, _gmsOvertime = 7
}
in addGameStats s1 s2 `shouldBe` expected
pPointsSpec :: Spec
pPointsSpec = describe "pPoints" $ mapM_
(\(goals, assists, points) -> let