implemented modifyPlayer
This commit is contained in:
parent
625d9c616a
commit
8c8a2d52a6
|
@ -126,7 +126,8 @@ module Mtlstats.Types (
|
|||
-- ** Player Helpers
|
||||
pPoints,
|
||||
playerSearch,
|
||||
playerSearchExact
|
||||
playerSearchExact,
|
||||
modifyPlayer
|
||||
) where
|
||||
|
||||
import Control.Monad.Trans.State (StateT)
|
||||
|
@ -692,3 +693,18 @@ playerSearchExact sStr =
|
|||
filter (match sStr) .
|
||||
zip [0..]
|
||||
where match sStr (_, p) = p^.pName == sStr
|
||||
|
||||
-- | Modifies a player with a given name
|
||||
modifyPlayer
|
||||
:: (Player -> Player)
|
||||
-- ^ The modification function
|
||||
-> String
|
||||
-- ^ The player's name
|
||||
-> [Player]
|
||||
-- ^ The list of players to modify
|
||||
-> [Player]
|
||||
-- ^ The modified list
|
||||
modifyPlayer f n = map
|
||||
(\p -> if p^.pName == n
|
||||
then f p
|
||||
else p)
|
||||
|
|
|
@ -57,6 +57,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
pPointsSpec
|
||||
playerSearchSpec
|
||||
playerSearchExactSpec
|
||||
modifyPlayerSpec
|
||||
Menu.spec
|
||||
|
||||
playerSpec :: Spec
|
||||
|
@ -552,6 +553,31 @@ playerSearchExactSpec = describe "playerSearchExact" $ mapM_
|
|||
, ( "", Nothing )
|
||||
]
|
||||
|
||||
modifyPlayerSpec :: Spec
|
||||
modifyPlayerSpec = describe "modifyPlayer" $ mapM_
|
||||
(\(pName, j, b, s) -> let
|
||||
modifier = pLifetime.psGoals .~ 1
|
||||
players = modifyPlayer modifier pName [joe, bob, steve]
|
||||
in context ("modify " ++ pName) $ do
|
||||
|
||||
context "Joe's lifetime goals" $
|
||||
it ("should be " ++ show j) $
|
||||
head players ^. pLifetime.psGoals `shouldBe` j
|
||||
|
||||
context "Bob's lifetime goals" $
|
||||
it ("should be " ++ show b) $
|
||||
(players !! 1) ^. pLifetime.psGoals `shouldBe` b
|
||||
|
||||
context "Steve's lifetime goals" $
|
||||
it ("should be " ++ show s) $
|
||||
last players ^. pLifetime.psGoals `shouldBe` s)
|
||||
-- player name, Joe's goals, Bob's goals, Steve's goals
|
||||
[ ( "Joe", 1, 0, 0 )
|
||||
, ( "Bob", 0, 1, 0 )
|
||||
, ( "Steve", 0, 0, 1 )
|
||||
, ( "Sam", 0, 0, 0 )
|
||||
]
|
||||
|
||||
joe :: Player
|
||||
joe = newPlayer 2 "Joe" "center"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user