Skip to content

Commit d96829d

Browse files
committed
Test Read/Show instances
1 parent b233955 commit d96829d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tests/HashMapProperties.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Test.Framework.Providers.QuickCheck2 (testProperty)
2121

2222
-- Key type that generates more hash collisions.
2323
newtype Key = K { unK :: Int }
24-
deriving (Arbitrary, Eq, Ord, Show)
24+
deriving (Arbitrary, Eq, Ord, Read, Show)
2525

2626
instance Hashable Key where
2727
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
@@ -38,6 +38,9 @@ pEq xs = (M.fromList xs ==) `eq` (HM.fromList xs ==)
3838
pNeq :: [(Key, Int)] -> [(Key, Int)] -> Bool
3939
pNeq xs = (M.fromList xs /=) `eq` (HM.fromList xs /=)
4040

41+
pReadShow :: [(Key, Int)] -> Bool
42+
pReadShow xs = M.fromList xs == read (show (M.fromList xs))
43+
4144
pFunctor :: [(Key, Int)] -> Bool
4245
pFunctor = fmap (+ 1) `eq_` fmap (+ 1)
4346

@@ -192,6 +195,7 @@ tests =
192195
testGroup "instances"
193196
[ testProperty "==" pEq
194197
, testProperty "/=" pNeq
198+
, testProperty "Read/Show" pReadShow
195199
, testProperty "Functor" pFunctor
196200
, testProperty "Foldable" pFoldable
197201
]

tests/HashSetProperties.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Test.Framework.Providers.QuickCheck2 (testProperty)
1616

1717
-- Key type that generates more hash collisions.
1818
newtype Key = K { unK :: Int }
19-
deriving (Arbitrary, Enum, Eq, Integral, Num, Ord, Show, Real)
19+
deriving (Arbitrary, Enum, Eq, Integral, Num, Ord, Read, Show, Real)
2020

2121
instance Hashable Key where
2222
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
@@ -33,6 +33,9 @@ pEq xs = (Set.fromList xs ==) `eq` (S.fromList xs ==)
3333
pNeq :: [Key] -> [Key] -> Bool
3434
pNeq xs = (Set.fromList xs /=) `eq` (S.fromList xs /=)
3535

36+
pReadShow :: [Key] -> Bool
37+
pReadShow xs = Set.fromList xs == read (show (Set.fromList xs))
38+
3639
pFoldable :: [Int] -> Bool
3740
pFoldable = (L.sort . Foldable.foldr (:) []) `eq`
3841
(L.sort . Foldable.foldr (:) [])
@@ -111,6 +114,7 @@ tests =
111114
testGroup "instances"
112115
[ testProperty "==" pEq
113116
, testProperty "/=" pNeq
117+
, testProperty "Read/Show" pReadShow
114118
, testProperty "Foldable" pFoldable
115119
]
116120
-- Basic interface

0 commit comments

Comments
 (0)