implemented playerSearchExact
This commit is contained in:
parent
d4cfbcb968
commit
8277f8bac7
|
@ -121,7 +121,8 @@ module Mtlstats.Types (
|
|||
addGameStats,
|
||||
-- ** Player Helpers
|
||||
pPoints,
|
||||
playerSearch
|
||||
playerSearch,
|
||||
playerSearchExact
|
||||
) where
|
||||
|
||||
import Control.Monad.Trans.State (StateT)
|
||||
|
@ -138,6 +139,7 @@ import Data.Aeson
|
|||
, (.=)
|
||||
)
|
||||
import Data.List (isInfixOf)
|
||||
import Data.Maybe (listToMaybe)
|
||||
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
||||
import Lens.Micro.TH (makeLenses)
|
||||
import qualified UI.NCurses as C
|
||||
|
@ -651,3 +653,17 @@ playerSearch sStr =
|
|||
filter (match sStr) .
|
||||
zip [0..]
|
||||
where match sStr (_, p) = sStr `isInfixOf` (p^.pName)
|
||||
|
||||
-- | Searches for a player by exact match on name
|
||||
playerSearchExact
|
||||
:: String
|
||||
-- ^ The player's name
|
||||
-> [Player]
|
||||
-- ^ The list of players to search
|
||||
-> Maybe (Int, Player)
|
||||
-- ^ The player's index and value
|
||||
playerSearchExact sStr =
|
||||
listToMaybe .
|
||||
filter (match sStr) .
|
||||
zip [0..]
|
||||
where match sStr (_, p) = p^.pName == sStr
|
||||
|
|
|
@ -56,6 +56,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||
addGameStatsSpec
|
||||
pPointsSpec
|
||||
playerSearchSpec
|
||||
playerSearchExactSpec
|
||||
Menu.spec
|
||||
|
||||
playerSpec :: Spec
|
||||
|
@ -526,7 +527,26 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
|||
, ( "e", [(0, joe), (2, steve)] )
|
||||
, ( "x", [] )
|
||||
]
|
||||
where
|
||||
joe = newPlayer 2 "Joe" "center"
|
||||
bob = newPlayer 3 "Bob" "defense"
|
||||
steve = newPlayer 5 "Steve" "forward"
|
||||
|
||||
playerSearchExactSpec :: Spec
|
||||
playerSearchExactSpec = describe "playerSearchExact" $ mapM_
|
||||
(\(sStr, expected) -> context sStr $
|
||||
it ("should be " ++ show expected) $ let
|
||||
ps = [joe, bob, steve]
|
||||
in playerSearchExact sStr ps `shouldBe` expected)
|
||||
-- search, result
|
||||
[ ( "Joe", Just (0, joe) )
|
||||
, ( "Bob", Just (1, bob) )
|
||||
, ( "Steve", Just (2, steve) )
|
||||
, ( "Sam", Nothing )
|
||||
, ( "", Nothing )
|
||||
]
|
||||
|
||||
joe :: Player
|
||||
joe = newPlayer 2 "Joe" "center"
|
||||
|
||||
bob :: Player
|
||||
bob = newPlayer 3 "Bob" "defense"
|
||||
|
||||
steve :: Player
|
||||
steve = newPlayer 5 "Steve" "forward"
|
||||
|
|
Loading…
Reference in New Issue
Block a user