@@ -45,6 +45,7 @@ main = defaultMain $ testGroup "intmap-properties"
45
45
, testCase " member" test_member
46
46
, testCase " notMember" test_notMember
47
47
, testCase " lookup" test_lookup
48
+ , testCase " query " test_query
48
49
, testCase " findWithDefault" test_findWithDefault
49
50
, testCase " lookupLT" test_lookupLT
50
51
, testCase " lookupGT" test_lookupGT
@@ -295,18 +296,42 @@ test_notMember = do
295
296
296
297
test_lookup :: Assertion
297
298
test_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
300
306
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 )]
304
310
employeeCurrency :: Int -> Maybe Int
305
311
employeeCurrency name = do
306
312
dept <- lookup name employeeDept
307
313
country <- lookup dept deptCountry
308
314
lookup country countryCurrency
309
315
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
+
310
335
test_findWithDefault :: Assertion
311
336
test_findWithDefault = do
312
337
findWithDefault ' x' 1 (fromList [(5 ,' a' ), (3 ,' b' )]) @?= ' x'
0 commit comments