implemented unaccountedPoints helper function
This commit is contained in:
parent
926a125692
commit
2ff8cff1c8
@ -114,6 +114,7 @@ module Mtlstats.Types (
|
|||||||
gameWon,
|
gameWon,
|
||||||
gameLost,
|
gameLost,
|
||||||
gameTied,
|
gameTied,
|
||||||
|
unaccountedPoints,
|
||||||
-- ** GameStats Helpers
|
-- ** GameStats Helpers
|
||||||
gmsGames,
|
gmsGames,
|
||||||
gmsPoints,
|
gmsPoints,
|
||||||
@ -609,6 +610,13 @@ gameLost gs = do
|
|||||||
gameTied :: GameState -> Maybe Bool
|
gameTied :: GameState -> Maybe Bool
|
||||||
gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
|
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
|
-- | Calculates the number of games played
|
||||||
gmsGames :: GameStats -> Int
|
gmsGames :: GameStats -> Int
|
||||||
gmsGames gs = gs^.gmsWins + gs^.gmsLosses + gs^.gmsOvertime
|
gmsGames gs = gs^.gmsWins + gs^.gmsLosses + gs^.gmsOvertime
|
||||||
|
@ -50,6 +50,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||||||
gameWonSpec
|
gameWonSpec
|
||||||
gameLostSpec
|
gameLostSpec
|
||||||
gameTiedSpec
|
gameTiedSpec
|
||||||
|
unaccountedPointsSpec
|
||||||
gmsGamesSpec
|
gmsGamesSpec
|
||||||
gmsPointsSpec
|
gmsPointsSpec
|
||||||
addGameStatsSpec
|
addGameStatsSpec
|
||||||
@ -399,6 +400,35 @@ gameTiedSpec = describe "gameTied" $ mapM_
|
|||||||
, ( Just 1, Just 2, Just False )
|
, ( 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 :: Spec
|
||||||
gmsGamesSpec = describe "gmsGames" $ mapM_
|
gmsGamesSpec = describe "gmsGames" $ mapM_
|
||||||
(\(w, l, ot, expected) -> let
|
(\(w, l, ot, expected) -> let
|
||||||
|
Loading…
x
Reference in New Issue
Block a user