@@ -10,7 +10,7 @@ import Data.Hashable (Hashable(hashWithSalt))
10
10
import qualified Data.List as L
11
11
import qualified Data.HashSet as S
12
12
import qualified Data.Set as Set
13
- import Test.QuickCheck (Arbitrary )
13
+ import Test.QuickCheck (Arbitrary , Property , (==>) , (===) )
14
14
import Test.Framework (Test , defaultMain , testGroup )
15
15
import Test.Framework.Providers.QuickCheck2 (testProperty )
16
16
@@ -40,6 +40,19 @@ pFoldable :: [Int] -> Bool
40
40
pFoldable = (L. sort . Foldable. foldr (:) [] ) `eq`
41
41
(L. sort . Foldable. foldr (:) [] )
42
42
43
+ pPermutationEq :: [Key ] -> [Int ] -> Bool
44
+ pPermutationEq xs is = S. fromList xs == S. fromList ys
45
+ where
46
+ ys = L. map snd . L. sort . L. zip (is ++ [L. maximum (0 : is) + 1 .. ]) $ xs
47
+
48
+ pHashable :: [Key ] -> [Int ] -> Int -> Property
49
+ pHashable xs is salt =
50
+ x == y ==> hashWithSalt salt x === hashWithSalt salt y
51
+ where
52
+ ys = L. map snd . L. sort . L. zip (is ++ [L. maximum (0 : is) + 1 .. ]) $ xs
53
+ x = S. fromList xs
54
+ y = S. fromList ys
55
+
43
56
------------------------------------------------------------------------
44
57
-- ** Basic interface
45
58
@@ -113,9 +126,11 @@ tests =
113
126
-- Instances
114
127
testGroup " instances"
115
128
[ testProperty " ==" pEq
129
+ , testProperty " Permutation ==" pPermutationEq
116
130
, testProperty " /=" pNeq
117
131
, testProperty " Read/Show" pReadShow
118
132
, testProperty " Foldable" pFoldable
133
+ , testProperty " Hashable" pHashable
119
134
]
120
135
-- Basic interface
121
136
, testGroup " basic interface"
0 commit comments