diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 96fcd72..3700b3f 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -97,6 +97,8 @@ module Mtlstats.Types ( gameWon, gameLost, gameTied, + -- ** GameStats Helpers + gmsPoints, -- ** Player Helpers pPoints ) where @@ -506,6 +508,10 @@ gameLost gs = (<) <$> teamScore gs <*> otherScore gs gameTied :: GameState -> Maybe Bool gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore +-- | Calculates the number of points +gmsPoints :: GameStats -> Int +gmsPoints gs = 2 * gs^.gmsWins + gs^. gmsOvertime + -- | 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 8b8fe52..599f8e6 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -46,6 +46,7 @@ spec = describe "Mtlstats.Types" $ do gameWonSpec gameLostSpec gameTiedSpec + gmsPointsSpec pPointsSpec Menu.spec @@ -320,6 +321,26 @@ gameTiedSpec = describe "gameTied" $ mapM_ , ( Just 1, Just 2, Just False ) ] +gmsPointsSpec :: Spec +gmsPointsSpec = describe "gmsPoints" $ mapM_ + (\(w, l, ot, expected) -> let + gs = GameStats + { _gmsWins = w + , _gmsLosses = l + , _gmsOvertime = ot + } + in context (show gs) $ + it ("should be " ++ show expected) $ + gmsPoints gs `shouldBe` expected) + -- wins, losses, overtime, expected + [ ( 0, 0, 0, 0 ) + , ( 1, 0, 0, 2 ) + , ( 0, 1, 0, 0 ) + , ( 0, 1, 1, 1 ) + , ( 1, 1, 1, 3 ) + , ( 2, 4, 3, 7 ) + ] + pPointsSpec :: Spec pPointsSpec = describe "pPoints" $ mapM_ (\(goals, assists, points) -> let