@@ -45,6 +45,7 @@ main = defaultMain $ testGroup "intmap-properties"
4545 , testCase " member" test_member
4646 , testCase " notMember" test_notMember
4747 , testCase " lookup" test_lookup
48+ , testCase " query " test_query
4849 , testCase " findWithDefault" test_findWithDefault
4950 , testCase " lookupLT" test_lookupLT
5051 , testCase " lookupGT" test_lookupGT
@@ -295,18 +296,42 @@ test_notMember = do
295296
296297test_lookup :: Assertion
297298test_lookup = do
298- employeeCurrency 1 @?= Just 1
299- employeeCurrency 2 @?= Nothing
299+ employeeCurrency 1 @?= Just 1
300+ employeeCurrency 2 @?= Just 2
301+ employeeCurrency 3 @?= Just 3
302+ employeeCurrency 4 @?= Just 4
303+ employeeCurrency 5 @?= Nothing
304+ employeeCurrency (2 ^ 10 ) @?= Just 42
305+ employeeCurrency 6 @?= Nothing
300306 where
301- employeeDept = fromList( [(1 ,2 ), (3 , 1 )])
302- deptCountry = fromList( [(1 ,1 ), (2 ,2 )])
303- countryCurrency = fromList( [(1 , 2 ), (2 , 1 )])
307+ employeeDept = fromList [(1 ,2 ), (2 , 14 ), ( 3 , 10 ), ( 4 , 18 ), ( 2 ^ 10 , 100 )]
308+ deptCountry = fromList [(1 ,1 ), (14 , 14 ), ( 10 , 10 ), ( 18 , 18 ), ( 100 , 100 ), ( 2 ,2 )]
309+ countryCurrency = fromList [(1 , 2 ), (2 , 1 ), ( 14 , 2 ), ( 10 , 3 ), ( 18 , 4 ), ( 100 , 42 )]
304310 employeeCurrency :: Int -> Maybe Int
305311 employeeCurrency name = do
306312 dept <- lookup name employeeDept
307313 country <- lookup dept deptCountry
308314 lookup country countryCurrency
309315
316+ test_query :: Assertion
317+ test_query = do
318+ employeeCurrency 1 @?= Just 1
319+ employeeCurrency 2 @?= Just 2
320+ employeeCurrency 3 @?= Just 3
321+ employeeCurrency 4 @?= Just 4
322+ employeeCurrency 5 @?= Nothing
323+ employeeCurrency (2 ^ 10 ) @?= Just 42
324+ employeeCurrency 6 @?= Nothing
325+ where
326+ employeeDept = fromList [(1 ,2 ), (2 , 14 ), (3 , 10 ), (4 , 18 ), (2 ^ 10 , 100 )]
327+ deptCountry = fromList [(1 ,1 ), (14 , 14 ), (10 , 10 ), (18 , 18 ), (100 , 100 ), (2 ,2 )]
328+ countryCurrency = fromList [(1 , 2 ), (2 , 1 ), (14 , 2 ), (10 , 3 ), (18 , 4 ), (100 , 42 )]
329+ employeeCurrency :: Int -> Maybe Int
330+ employeeCurrency name = do
331+ dept <- query name employeeDept
332+ country <- query dept deptCountry
333+ query country countryCurrency
334+
310335test_findWithDefault :: Assertion
311336test_findWithDefault = do
312337 findWithDefault ' x' 1 (fromList [(5 ,' a' ), (3 ,' b' )]) @?= ' x'
0 commit comments