implemented posSearchExact

This commit is contained in:
Jonathan Lamothe 2020-02-12 00:27:28 -05:00
parent 25e4929f0b
commit a2968595d8
2 changed files with 22 additions and 1 deletions

View File

@ -54,7 +54,12 @@ posSearchExact
-- ^ The database -- ^ The database
-> Maybe Int -> Maybe Int
-- ^ The index of the result (or 'Nothing' if not found) -- ^ The index of the result (or 'Nothing' if not found)
posSearchExact = undefined posSearchExact sStr db = case filter sFunc $ zip [0..] ps of
[] -> Nothing
(n,_):_ -> Just n
where
sFunc (_, pos) = sStr == pos
ps = getPositions db
-- | Builds a callback function for when a 'Player' position is -- | Builds a callback function for when a 'Player' position is
-- selected -- selected

View File

@ -30,6 +30,7 @@ import Mtlstats.Types
spec :: Spec spec :: Spec
spec = describe "Position" $ do spec = describe "Position" $ do
posSearchSpec posSearchSpec
posSearchExactSpec
getPositionsSpec getPositionsSpec
posSearchSpec :: Spec posSearchSpec :: Spec
@ -48,6 +49,21 @@ posSearchSpec = describe "posSearch" $ mapM_
) )
] ]
posSearchExactSpec :: Spec
posSearchExactSpec = describe "posSearchExact" $ mapM_
(\(input, expected) -> context ("input: " ++ show input) $
it ("should be " ++ show expected) $
posSearchExact input db `shouldBe` expected)
-- input, expected
[ ( "foo", Just 2 )
, ( "FOO", Nothing )
, ( "bar", Just 0 )
, ( "baz", Just 1 )
, ( "a", Nothing )
, ( "quux", Nothing )
]
getPositionsSpec :: Spec getPositionsSpec :: Spec
getPositionsSpec = describe "getPositions" $ let getPositionsSpec = describe "getPositions" $ let
expected = ["bar", "baz", "foo"] expected = ["bar", "baz", "foo"]