implemented goalieSearchExact

This commit is contained in:
Jonathan Lamothe 2019-10-30 23:18:15 -04:00
parent 7e19ee072f
commit 12c8d0bdd6
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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"