diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 1dd71e6..faa5021 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -114,6 +114,7 @@ module Mtlstats.Types ( gameWon, gameLost, gameTied, + unaccountedPoints, -- ** GameStats Helpers gmsGames, gmsPoints, @@ -609,6 +610,13 @@ gameLost gs = do gameTied :: GameState -> Maybe Bool gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore +-- | Checks for unaccounted points +unaccountedPoints :: GameState -> Maybe Bool +unaccountedPoints gs = do + scored <- teamScore gs + let accounted = gs^.pointsAccounted + Just $ scored > accounted + -- | Calculates the number of games played gmsGames :: GameStats -> Int gmsGames gs = gs^.gmsWins + gs^.gmsLosses + gs^.gmsOvertime diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 85c008c..60e1f6a 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -50,6 +50,7 @@ spec = describe "Mtlstats.Types" $ do gameWonSpec gameLostSpec gameTiedSpec + unaccountedPointsSpec gmsGamesSpec gmsPointsSpec addGameStatsSpec @@ -399,6 +400,35 @@ gameTiedSpec = describe "gameTied" $ mapM_ , ( Just 1, Just 2, Just False ) ] +unaccountedPointsSpec :: Spec +unaccountedPointsSpec = describe "unaccounted points" $ do + context "no data" $ + it "should return Nothing" $ + unaccountedPoints newGameState `shouldBe` Nothing + + context "unaccounted points" $ + it "should return True" $ let + gs = newGameState + & gameType ?~ HomeGame + & homeScore ?~ 1 + in unaccountedPoints gs `shouldBe` Just True + + context "all points accounted" $ + it "should return False" $ let + gs = newGameState + & gameType ?~ HomeGame + & homeScore ?~ 1 + & pointsAccounted .~ 1 + in unaccountedPoints gs `shouldBe` Just False + + context "more points accounted" $ + it "should return True" $ let + gs = newGameState + & gameType ?~ HomeGame + & homeScore ?~ 1 + & pointsAccounted .~ 2 + in unaccountedPoints gs `shouldBe` Just False + gmsGamesSpec :: Spec gmsGamesSpec = describe "gmsGames" $ mapM_ (\(w, l, ot, expected) -> let