implemented playerSearchExact
This commit is contained in:
@@ -121,7 +121,8 @@ module Mtlstats.Types (
|
|||||||
addGameStats,
|
addGameStats,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
pPoints,
|
pPoints,
|
||||||
playerSearch
|
playerSearch,
|
||||||
|
playerSearchExact
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (StateT)
|
import Control.Monad.Trans.State (StateT)
|
||||||
@@ -138,6 +139,7 @@ import Data.Aeson
|
|||||||
, (.=)
|
, (.=)
|
||||||
)
|
)
|
||||||
import Data.List (isInfixOf)
|
import Data.List (isInfixOf)
|
||||||
|
import Data.Maybe (listToMaybe)
|
||||||
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
||||||
import Lens.Micro.TH (makeLenses)
|
import Lens.Micro.TH (makeLenses)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
@@ -651,3 +653,17 @@ playerSearch sStr =
|
|||||||
filter (match sStr) .
|
filter (match sStr) .
|
||||||
zip [0..]
|
zip [0..]
|
||||||
where match sStr (_, p) = sStr `isInfixOf` (p^.pName)
|
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
|
addGameStatsSpec
|
||||||
pPointsSpec
|
pPointsSpec
|
||||||
playerSearchSpec
|
playerSearchSpec
|
||||||
|
playerSearchExactSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
|
||||||
playerSpec :: Spec
|
playerSpec :: Spec
|
||||||
@@ -526,7 +527,26 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
|||||||
, ( "e", [(0, joe), (2, steve)] )
|
, ( "e", [(0, joe), (2, steve)] )
|
||||||
, ( "x", [] )
|
, ( "x", [] )
|
||||||
]
|
]
|
||||||
where
|
|
||||||
|
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"
|
joe = newPlayer 2 "Joe" "center"
|
||||||
|
|
||||||
|
bob :: Player
|
||||||
bob = newPlayer 3 "Bob" "defense"
|
bob = newPlayer 3 "Bob" "defense"
|
||||||
|
|
||||||
|
steve :: Player
|
||||||
steve = newPlayer 5 "Steve" "forward"
|
steve = newPlayer 5 "Steve" "forward"
|
||||||
|
|||||||
Reference in New Issue
Block a user