implemented unaccountedPoints helper function
This commit is contained in:
parent
926a125692
commit
2ff8cff1c8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user