diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index a310c51..7d13fc5 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -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 diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index c9f7257..b8bd0bb 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -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