@@ -7,7 +7,7 @@ import Data.Hashable (Hashable(hashWithSalt))
77import Test.ChasingBottoms.IsBottom
88import Test.Framework (Test , defaultMain , testGroup )
99import Test.Framework.Providers.QuickCheck2 (testProperty )
10- import Test.QuickCheck (Arbitrary (arbitrary ), Property , (===) , (.&&.) )
10+ import Test.QuickCheck (Arbitrary (arbitrary ), CoArbitrary , Property , (===) , (.&&.) )
1111import Test.QuickCheck.Function
1212import Test.QuickCheck.Poly (A )
1313import Data.Maybe (fromMaybe , isJust )
@@ -25,7 +25,10 @@ import qualified Data.HashMap.Strict as HM
2525
2626-- Key type that generates more hash collisions.
2727newtype Key = K { unK :: Int }
28- deriving (Arbitrary , Eq , Ord , Show )
28+ deriving (Arbitrary , CoArbitrary , Eq , Ord , Show )
29+
30+ instance Function Key where
31+ function = functionMap unK K
2932
3033instance Hashable Key where
3134 hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
@@ -71,23 +74,25 @@ pInsertKeyStrict v m = isBottom $ HM.insert bottom v m
7174pInsertValueStrict :: Key -> HashMap Key Int -> Bool
7275pInsertValueStrict k m = isBottom $ HM. insert k bottom m
7376
74- pInsertWithKeyStrict :: (Int -> Int -> Int ) -> Int -> HashMap Key Int -> Bool
75- pInsertWithKeyStrict f v m = isBottom $ HM. insertWith f bottom v m
77+ pInsertWithKeyStrict :: Fun (Int , Int ) Int -> Int -> HashMap Key Int -> Bool
78+ pInsertWithKeyStrict f v m =
79+ isBottom $ HM. insertWith (curry . apply $ f) bottom v m
7680
77- pInsertWithValueStrict :: (Int -> Int -> Int ) -> Key -> Int -> HashMap Key Int
81+ pInsertWithValueStrict :: Fun (Int , Int ) Int -> Key -> Int -> HashMap Key Int
7882 -> Bool
7983pInsertWithValueStrict f k v m
8084 | HM. member k m = isBottom $ HM. insertWith (const2 bottom) k v m
81- | otherwise = isBottom $ HM. insertWith f k bottom m
85+ | otherwise = isBottom $ HM. insertWith ( curry . apply $ f) k bottom m
8286
83- pInsertWithKeyKeyStrict :: (Key -> Int -> Int -> Int ) -> Int -> HashMap Key Int -> Bool
84- pInsertWithKeyKeyStrict f v m = isBottom $ HM. insertWithKey f bottom v m
87+ pInsertWithKeyKeyStrict :: Fun (Key , (Int , Int )) Int -> Int -> HashMap Key Int -> Bool
88+ pInsertWithKeyKeyStrict f v m =
89+ isBottom $ HM. insertWithKey (curry . curry (apply f)) bottom v m
8590
86- pInsertWithKeyValueStrict :: (Key -> Int -> Int -> Int ) -> Key -> Int -> HashMap Key Int
91+ pInsertWithKeyValueStrict :: Fun (Key , ( Int , Int )) Int -> Key -> Int -> HashMap Key Int
8792 -> Bool
8893pInsertWithKeyValueStrict f k v m
8994 | HM. member k m = isBottom $ HM. insertWithKey (const2 bottom) k v m
90- | otherwise = isBottom $ HM. insertWithKey f k bottom m
95+ | otherwise = isBottom $ HM. insertWithKey ( curry . curry (apply f)) k bottom m
9196
9297pFromListKeyStrict :: Bool
9398pFromListKeyStrict = isBottom $ HM. fromList [(undefined :: Key , 1 :: Int )]
0 commit comments