implemented playerIsActive
This commit is contained in:
parent
363d0cb2d3
commit
d338930800
|
@ -133,6 +133,7 @@ module Mtlstats.Types (
|
|||
playerSearchExact,
|
||||
modifyPlayer,
|
||||
playerSummary,
|
||||
playerIsActive,
|
||||
-- ** PlayerStats Helpers
|
||||
psPoints,
|
||||
addPlayerStats
|
||||
|
@ -736,6 +737,16 @@ playerSummary :: Player -> String
|
|||
playerSummary p =
|
||||
p^.pName ++ " (" ++ show (p^.pNumber) ++ ") " ++ p^.pPosition
|
||||
|
||||
-- | Determines whether or not a player has been active in the current
|
||||
-- season/year
|
||||
playerIsActive :: Player -> Bool
|
||||
playerIsActive = do
|
||||
stats <- (^.pYtd)
|
||||
return
|
||||
$ stats^.psGoals /= 0
|
||||
|| stats^.psAssists /= 0
|
||||
|| stats^.psPMin /= 0
|
||||
|
||||
-- | Calculates a player's points
|
||||
psPoints :: PlayerStats -> Int
|
||||
psPoints s = s^.psGoals + s^.psAssists
|
||||
|
|
|
@ -58,6 +58,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
playerSearchExactSpec
|
||||
modifyPlayerSpec
|
||||
playerSummarySpec
|
||||
playerIsActiveSpec
|
||||
psPointsSpec
|
||||
addPlayerStatsSpec
|
||||
Menu.spec
|
||||
|
@ -567,6 +568,26 @@ playerSummarySpec = describe "playerSummary" $
|
|||
it "should be \"Joe (2) center\"" $
|
||||
playerSummary joe `shouldBe` "Joe (2) center"
|
||||
|
||||
playerIsActiveSpec :: Spec
|
||||
playerIsActiveSpec = describe "playerIsActive" $ do
|
||||
let
|
||||
pState = newPlayerStats
|
||||
& psGoals .~ 10
|
||||
& psAssists .~ 11
|
||||
& psPMin .~ 12
|
||||
player = newPlayer 1 "Joe" "centre" & pLifetime .~ pState
|
||||
|
||||
mapM_
|
||||
(\(label, player', expected) -> context label $
|
||||
it ("should be " ++ show expected) $
|
||||
playerIsActive player' `shouldBe` expected)
|
||||
-- label, player, expected
|
||||
[ ( "not active", player, False )
|
||||
, ( "has goal", player & pYtd.psGoals .~ 1, True )
|
||||
, ( "has assist", player & pYtd.psAssists .~ 1, True )
|
||||
, ( "has penalty minute", player & pYtd.psPMin .~ 1, True )
|
||||
]
|
||||
|
||||
psPointsSpec :: Spec
|
||||
psPointsSpec = describe "psPoints" $ mapM_
|
||||
(\(goals, assists, points) -> let
|
||||
|
|
Loading…
Reference in New Issue
Block a user