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