made playerSearch and goalieSearch case insensitive
This commit is contained in:
parent
f7cfd5d835
commit
8af7974c8f
|
@ -192,6 +192,7 @@ import Data.Aeson
|
|||
, (.!=)
|
||||
, (.=)
|
||||
)
|
||||
import Data.Char (toUpper)
|
||||
import Data.List (isInfixOf)
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe (listToMaybe)
|
||||
|
@ -904,7 +905,7 @@ playerSearch
|
|||
-- ^ The matching players with their index numbers
|
||||
playerSearch sStr =
|
||||
filter match . zip [0..]
|
||||
where match (_, p) = sStr `isInfixOf` (p^.pName)
|
||||
where match (_, p) = map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
||||
|
||||
-- | Searches for a player by exact match on name
|
||||
playerSearchExact
|
||||
|
@ -967,8 +968,9 @@ goalieSearch
|
|||
-- ^ The list to search
|
||||
-> [(Int, Goalie)]
|
||||
-- ^ The search results with their corresponding index numbers
|
||||
goalieSearch sStr = filter (\(_, goalie) -> sStr `isInfixOf` (goalie^.gName)) .
|
||||
zip [0..]
|
||||
goalieSearch sStr =
|
||||
filter match . zip [0..]
|
||||
where match (_, g) = map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
||||
|
||||
-- | Searches a list of goalies for an exact match
|
||||
goalieSearchExact
|
||||
|
|
|
@ -591,7 +591,7 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
|||
ps = [joe, bob, steve]
|
||||
in playerSearch sStr ps `shouldBe` expected)
|
||||
-- search, result
|
||||
[ ( "Joe", [(0, joe)] )
|
||||
[ ( "joe", [(0, joe)] )
|
||||
, ( "o", [(0, joe), (1, bob)] )
|
||||
, ( "e", [(0, joe), (2, steve)] )
|
||||
, ( "x", [] )
|
||||
|
@ -725,8 +725,8 @@ goalieSearchSpec = describe "goalieSearch" $ do
|
|||
goalieSearch "x" goalies `shouldBe` []
|
||||
|
||||
context "exact match" $
|
||||
it "should return Steve" $
|
||||
goalieSearch "Bob" goalies `shouldBe` [result 1]
|
||||
it "should return Bob" $
|
||||
goalieSearch "bob" goalies `shouldBe` [result 1]
|
||||
|
||||
goalieSearchExactSpec :: Spec
|
||||
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
||||
|
|
Loading…
Reference in New Issue
Block a user