Skip to content

Commit 93fd868

Browse files
committed
Bunch of changes
* Continue set and map combination rewrites. * Add bias tests to `Data.Set` suite. * Replace `Arbitrary` instance for sets. * Use specialized function to produce pairs of sets for combination tests. This is a horribly large and incomplete commit, but it all works and I need to move on to some other things. Sorry, world.
1 parent 11cd73c commit 93fd868

File tree

3 files changed

+182
-74
lines changed

3 files changed

+182
-74
lines changed

containers.cabal

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,8 @@ Test-suite map-lazy-properties
220220
QuickCheck,
221221
test-framework,
222222
test-framework-hunit,
223-
test-framework-quickcheck2
224-
if impl (ghc < 7.10)
225-
-- only needed for base < 4.8 to get Identity
226-
build-depends: transformers
223+
test-framework-quickcheck2,
224+
transformers
227225

228226
Test-suite map-strict-properties
229227
hs-source-dirs: tests, .
@@ -237,15 +235,12 @@ Test-suite map-strict-properties
237235
include-dirs: include
238236

239237
build-depends:
240-
-- only needed for base < 4.8 to get Identity
241238
HUnit,
242239
QuickCheck,
243240
test-framework,
244241
test-framework-hunit,
245-
test-framework-quickcheck2
246-
if impl (ghc < 7.10)
247-
-- only needed for base < 4.8 to get Identity
248-
build-depends: transformers
242+
test-framework-quickcheck2,
243+
transformers
249244

250245
Test-suite bitqueue-properties
251246
hs-source-dirs: tests, .
@@ -279,7 +274,8 @@ Test-suite set-properties
279274
QuickCheck,
280275
test-framework,
281276
test-framework-hunit,
282-
test-framework-quickcheck2
277+
test-framework-quickcheck2,
278+
transformers
283279

284280
Test-suite intmap-lazy-properties
285281
hs-source-dirs: tests, .

tests/map-properties.hs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ main = defaultMain
138138
, testCase "minViewWithKey" test_minViewWithKey
139139
, testCase "maxViewWithKey" test_maxViewWithKey
140140
, testCase "valid" test_valid
141-
, testProperty "unionWith3" prop_unionWith3
142141
, testProperty "valid" prop_valid
143142
, testProperty "insert to singleton" prop_singleton
144143
, testProperty "insert" prop_insert
@@ -214,7 +213,7 @@ main = defaultMain
214213
]
215214

216215
{--------------------------------------------------------------------
217-
Arbitrary, reasonably balanced trees
216+
Arbitrary trees
218217
--------------------------------------------------------------------}
219218
instance (Enum k,Arbitrary a) => Arbitrary (Map k a) where
220219
arbitrary = sized (arbtree 0 maxkey)
@@ -240,15 +239,15 @@ instance (Enum k,Arbitrary a) => Arbitrary (Map k a) where
240239

241240
-- A type with a peculiar Eq instance designed to make sure keys
242241
-- come from where they're supposed to.
243-
data OddEq a = OddEq Bool a deriving (Show)
244-
getOddEq :: OddEq a -> (Bool, a)
245-
getOddEq (OddEq b a) = (b, a)
242+
data OddEq a = OddEq a Bool deriving (Show)
243+
getOddEq :: OddEq a -> (a, Bool)
244+
getOddEq (OddEq a b) = (a, b)
246245
instance Arbitrary a => Arbitrary (OddEq a) where
247246
arbitrary = OddEq <$> arbitrary <*> arbitrary
248247
instance Eq a => Eq (OddEq a) where
249-
OddEq _ x == OddEq _ y = x == y
248+
OddEq x _ == OddEq y _ = x == y
250249
instance Ord a => Ord (OddEq a) where
251-
OddEq _ x `compare` OddEq _ y = x `compare` y
250+
OddEq x _ `compare` OddEq y _ = x `compare` y
252251

253252
------------------------------------------------------------------------
254253

@@ -984,22 +983,6 @@ prop_unionWith t1 t2 = (union t1 t2 == unionWith (\_ y -> y) t2 t1)
984983
prop_unionWith2 :: IMap -> IMap -> Bool
985984
prop_unionWith2 t1 t2 = valid (unionWithKey (\_ x y -> x+y) t1 t2)
986985

987-
prop_unionWith3 :: Fun (Int,Int) Int -> IMap -> IMap -> Property
988-
prop_unionWith3 f t1 t2 = valid uw .&&. uwUndone === uwEasyUndone
989-
where
990-
t1' :: Map (OddEq Int) Int
991-
t1' = mapKeysMonotonic (OddEq False) t1
992-
t2' :: Map (OddEq Int) Int
993-
t2' = mapKeysMonotonic (OddEq True) t2
994-
uw :: Map (OddEq Int) Int
995-
uw = unionWith (apply2 f) t1' t2'
996-
uwUndone :: [((Bool, Int), Int)]
997-
uwUndone = first getOddEq <$> toList uw
998-
uwEasy :: Map (OddEq Int) Int
999-
uwEasy = List.foldl' (\t (k1, v1) -> insertWith (apply2 f) k1 v1 t) t2' (toList t1')
1000-
uwEasyUndone :: [((Bool, Int), Int)]
1001-
uwEasyUndone = first getOddEq <$> toList uwEasy
1002-
1003986
prop_unionSum :: [(Int,Int)] -> [(Int,Int)] -> Bool
1004987
prop_unionSum xs ys
1005988
= sum (elems (unionWith (+) (fromListWith (+) xs) (fromListWith (+) ys)))

0 commit comments

Comments
 (0)