diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index c171676..a875aaf 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -854,7 +854,12 @@ goalieSearchExact -- ^ The list to search -> Maybe (Int, Goalie) -- ^ The result with its index number -goalieSearchExact = undefined +goalieSearchExact sStr goalies = let + results = filter (\(_, goalie) -> sStr == goalie^.gName) $ + zip [0..] goalies + in case results of + [] -> Nothing + result:_ -> Just result -- | Provides a description string for a 'Goalie' goalieSummary :: Goalie -> String diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 3312160..113f196 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -66,6 +66,7 @@ spec = describe "Mtlstats.Types" $ do psPointsSpec addPlayerStatsSpec goalieSearchSpec + goalieSearchExactSpec Menu.spec playerSpec :: Spec @@ -674,6 +675,30 @@ goalieSearchSpec = describe "goalieSearch" $ do it "should return Steve" $ goalieSearch "Bob" goalies `shouldBe` [result 1] +goalieSearchExactSpec :: Spec +goalieSearchExactSpec = describe "goalieSearchExact" $ do + let + goalies = + [ newGoalie 2 "Joe" + , newGoalie 3 "Bob" + , newGoalie 5 "Steve" + ] + result n = (n, goalies!!n) + + mapM_ + (\(name, num) -> context name $ + it ("should return " ++ name) $ + goalieSearchExact name goalies `shouldBe` Just (result num)) + -- name, num + [ ( "Joe", 0 ) + , ( "Bob", 1 ) + , ( "Steve", 2 ) + ] + + context "Greg" $ + it "should return Nothing" $ + goalieSearchExact "Greg" goalies `shouldBe` Nothing + joe :: Player joe = newPlayer 2 "Joe" "center"