From 74fd4fe2fb6c6b6ab951dc25599e1fad93063af0 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 9 Oct 2019 00:24:34 -0400 Subject: [PATCH] implemented addPlayerStats --- src/Mtlstats/Types.hs | 11 ++++++++++- test/TypesSpec.hs | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index ba821b6..65c9e1d 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -130,7 +130,9 @@ module Mtlstats.Types ( playerSearch, playerSearchExact, modifyPlayer, - playerSummary + playerSummary, + -- ** PlayerStats Helpers + addPlayerStats ) where import Control.Monad.Trans.State (StateT) @@ -725,3 +727,10 @@ modifyPlayer f n = map playerSummary :: Player -> String playerSummary p = p^.pName ++ " (" ++ show (p^.pNumber) ++ ") " ++ p^.pPosition + +-- | Adds two 'PlayerStats' together +addPlayerStats :: PlayerStats -> PlayerStats -> PlayerStats +addPlayerStats s1 s2 = newPlayerStats + & psGoals .~ s1^.psGoals + s2^.psGoals + & psAssists .~ s1^.psAssists + s2^.psAssists + & psPMin .~ s1^.psPMin + s2^.psPMin diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index ad3b03d..2fa4d83 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -59,6 +59,7 @@ spec = describe "Mtlstats.Types" $ do playerSearchExactSpec modifyPlayerSpec playerSummarySpec + addPlayerStatsSpec Menu.spec playerSpec :: Spec @@ -584,6 +585,33 @@ playerSummarySpec = describe "playerSummary" $ it "should be \"Joe (2) center\"" $ playerSummary joe `shouldBe` "Joe (2) center" +addPlayerStatsSpec :: Spec +addPlayerStatsSpec = describe "addPlayerStats" $ do + let + s1 + = newPlayerStats + & psGoals .~ 1 + & psAssists .~ 2 + & psPMin .~ 3 + s2 + = newPlayerStats + & psGoals .~ 4 + & psAssists .~ 5 + & psPMin .~ 6 + s3 = addPlayerStats s1 s2 + + describe "psGoals" $ + it "should be 5" $ + s3^.psGoals `shouldBe` 5 + + describe "psAssists" $ + it "should be 7" $ + s3^.psAssists `shouldBe` 7 + + describe "psPMin" $ + it "should be 9" $ + s3^.psPMin `shouldBe` 9 + joe :: Player joe = newPlayer 2 "Joe" "center"