From 8af7974c8fa67c5e3c0f0c0b69090ce31c75d734 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 30 Nov 2019 12:54:50 -0500 Subject: [PATCH] made playerSearch and goalieSearch case insensitive --- src/Mtlstats/Types.hs | 8 +++++--- test/TypesSpec.hs | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index de0c66e..6997628 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -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 diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 294d17d..1744669 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -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