implemented addPlayerStats
This commit is contained in:
parent
5f53413ef7
commit
74fd4fe2fb
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user