From 7e19ee072f7aba9a1890c1a67dab53fd6c17a491 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 30 Oct 2019 23:01:59 -0400 Subject: [PATCH] implemented goalieSearch --- src/Mtlstats/Types.hs | 3 ++- test/TypesSpec.hs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index a74618a..c171676 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -843,7 +843,8 @@ goalieSearch -- ^ The list to search -> [(Int, Goalie)] -- ^ The search results with their corresponding index numbers -goalieSearch = undefined +goalieSearch sStr = filter (\(_, goalie) -> sStr `isInfixOf` (goalie^.gName)) . + zip [0..] -- | Searches a list of goalies for an exact match goalieSearchExact diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index cbaf831..3312160 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -65,6 +65,7 @@ spec = describe "Mtlstats.Types" $ do playerIsActiveSpec psPointsSpec addPlayerStatsSpec + goalieSearchSpec Menu.spec playerSpec :: Spec @@ -651,6 +652,28 @@ addPlayerStatsSpec = describe "addPlayerStats" $ do it "should be 9" $ s3^.psPMin `shouldBe` 9 +goalieSearchSpec :: Spec +goalieSearchSpec = describe "goalieSearch" $ do + let + goalies = + [ newGoalie 2 "Joe" + , newGoalie 3 "Bob" + , newGoalie 5 "Steve" + ] + result n = (n, goalies!!n) + + context "partial match" $ + it "should return Joe and Steve" $ + goalieSearch "e" goalies `shouldBe` [result 0, result 2] + + context "no match" $ + it "should return an empty list" $ + goalieSearch "x" goalies `shouldBe` [] + + context "exact match" $ + it "should return Steve" $ + goalieSearch "Bob" goalies `shouldBe` [result 1] + joe :: Player joe = newPlayer 2 "Joe" "center"