Skip to content

Commit f9c1e89

Browse files
committed
Add and use applyFun3.
This function is only available in new versions of QuickCheck which we may not have for old GHC versions. This inlines the function here for portability. Skipping CI since there's still a known failure (pInsertWithKeyValueStrict). [ci skip]
1 parent 39c62c5 commit f9c1e89

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

tests/HashMapProperties.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import qualified Data.HashMap.Lazy as HM
1818
#endif
1919
import qualified Data.Map as M
2020
import Test.QuickCheck (Arbitrary, CoArbitrary, Property, (==>), (===))
21-
import Test.QuickCheck.Function (Fun, Function(function), apply, functionMap)
21+
import Test.QuickCheck.Function (Fun(Fun), Function(function), apply, functionMap)
2222
import Test.Framework (Test, defaultMain, testGroup)
2323
import Test.Framework.Providers.QuickCheck2 (testProperty)
2424

@@ -156,9 +156,14 @@ pInsertWith f k =
156156
M.insertWith f' k 1 `eq_` HM.insertWith f' k 1
157157
where f' = curry . apply $ f
158158

159-
pInsertWithKey :: Fun (Key, (Int, Int)) Int -> Key -> [(Key, Int)] -> Bool
159+
-- | Extracts the value of a ternary function.
160+
-- Copied from Test.QuickCheck.Function.applyFun3
161+
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
162+
applyFun3 (Fun _ f) a b c = f (a, b, c)
163+
164+
pInsertWithKey :: Fun (Key, Int, Int) Int -> Key -> [(Key, Int)] -> Bool
160165
pInsertWithKey f k = M.insertWithKey f' k 1 `eq_` HM.insertWithKey f' k 1
161-
where f' = curry . curry (apply f)
166+
where f' = applyFun3 f
162167

163168
pAdjust :: Key -> [(Key, Int)] -> Bool
164169
pAdjust k = M.adjust succ k `eq_` HM.adjust succ k

tests/Strictness.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,20 @@ pInsertWithValueStrict f k v m
8484
| HM.member k m = isBottom $ HM.insertWith (const2 bottom) k v m
8585
| otherwise = isBottom $ HM.insertWith (curry . apply $ f) k bottom m
8686

87-
pInsertWithKeyKeyStrict :: Fun (Key, (Int, Int)) Int -> Int -> HashMap Key Int -> Bool
87+
-- | Extracts the value of a ternary function.
88+
-- Copied from Test.QuickCheck.Function.applyFun3
89+
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
90+
applyFun3 (Fun _ f) a b c = f (a, b, c)
91+
92+
pInsertWithKeyKeyStrict :: Fun (Key, Int, Int) Int -> Int -> HashMap Key Int -> Bool
8893
pInsertWithKeyKeyStrict f v m =
89-
isBottom $ HM.insertWithKey (curry . curry (apply f)) bottom v m
94+
isBottom $ HM.insertWithKey (applyFun3 f) bottom v m
9095

91-
pInsertWithKeyValueStrict :: Fun (Key, (Int, Int)) Int -> Key -> Int -> HashMap Key Int
96+
pInsertWithKeyValueStrict :: Fun (Key, Int, Int) Int -> Key -> Int -> HashMap Key Int
9297
-> Bool
9398
pInsertWithKeyValueStrict f k v m
94-
| HM.member k m = isBottom $ HM.insertWithKey (const2 bottom) k v m
95-
| otherwise = isBottom $ HM.insertWithKey (curry . curry (apply f)) k bottom m
99+
| HM.member k m = isBottom $ HM.insertWithKey (const3 bottom) k v m
100+
| otherwise = isBottom $ HM.insertWithKey (applyFun3 f) k bottom m
96101

97102
pFromListKeyStrict :: Bool
98103
pFromListKeyStrict = isBottom $ HM.fromList [(undefined :: Key, 1 :: Int)]
@@ -206,3 +211,6 @@ keyStrict f m = isBottom $ f bottom m
206211

207212
const2 :: a -> b -> c -> a
208213
const2 x _ _ = x
214+
215+
const3 :: a -> b -> c -> d -> a
216+
const3 x _ _ _ = x

0 commit comments

Comments
 (0)