@@ -10,6 +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 Data.Ord (comparing )
13
14
import Test.QuickCheck (Arbitrary , Property , (==>) , (===) )
14
15
import Test.Framework (Test , defaultMain , testGroup )
15
16
import Test.Framework.Providers.QuickCheck2 (testProperty )
@@ -43,15 +44,21 @@ pFoldable = (L.sort . Foldable.foldr (:) []) `eq`
43
44
pPermutationEq :: [Key ] -> [Int ] -> Bool
44
45
pPermutationEq xs is = S. fromList xs == S. fromList ys
45
46
where
46
- ys = L. map snd . L. sort . L. zip (is ++ [L. maximum (0 : is) + 1 .. ]) $ xs
47
+ ys = shuffle is xs
48
+ shuffle idxs = L. map snd
49
+ . L. sortBy (comparing fst )
50
+ . L. zip (idxs ++ [L. maximum (0 : is) + 1 .. ])
47
51
48
52
pHashable :: [Key ] -> [Int ] -> Int -> Property
49
53
pHashable xs is salt =
50
54
x == y ==> hashWithSalt salt x === hashWithSalt salt y
51
55
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
56
+ ys = shuffle is xs
57
+ x = S. fromList xs
58
+ y = S. fromList ys
59
+ shuffle idxs = L. map snd
60
+ . L. sortBy (comparing fst )
61
+ . L. zip (idxs ++ [L. maximum (0 : is) + 1 .. ])
55
62
56
63
------------------------------------------------------------------------
57
64
-- ** Basic interface
0 commit comments