Skip to content

Commit 2b08194

Browse files
committed
Add Hashable HashMap test
1 parent 206b769 commit 2b08194

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/HashMapProperties.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import qualified Data.HashMap.Strict as HM
1616
import qualified Data.HashMap.Lazy as HM
1717
#endif
1818
import qualified Data.Map as M
19-
import Test.QuickCheck (Arbitrary, Property, (==>))
19+
import Test.QuickCheck (Arbitrary, Property, (==>), (===))
2020
import Test.Framework (Test, defaultMain, testGroup)
2121
import Test.Framework.Providers.QuickCheck2 (testProperty)
2222

@@ -49,6 +49,14 @@ pFoldable :: [(Int, Int)] -> Bool
4949
pFoldable = (L.sort . Foldable.foldr (:) []) `eq`
5050
(L.sort . Foldable.foldr (:) [])
5151

52+
pHashable :: [(Key, Int)] -> [Int] -> Int -> Property
53+
pHashable xs is salt =
54+
x == y ==> hashWithSalt salt x === hashWithSalt salt y
55+
where
56+
ys = L.map snd . L.sort . L.zip (is ++ [L.maximum (0:is) + 1..]) $ xs
57+
x = HM.fromList xs
58+
y = HM.fromList ys
59+
5260
------------------------------------------------------------------------
5361
-- ** Basic interface
5462

@@ -229,6 +237,7 @@ tests =
229237
, testProperty "Read/Show" pReadShow
230238
, testProperty "Functor" pFunctor
231239
, testProperty "Foldable" pFoldable
240+
, testProperty "Hashable" pHashable
232241
]
233242
-- Basic interface
234243
, testGroup "basic interface"

0 commit comments

Comments
 (0)