Skip to content

Commit 4c20c88

Browse files
committed
Reorganize test files.
Skipping CI, known test failure being investigated. [ci skip]
1 parent 5a6a974 commit 4c20c88

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

tests/HashMapProperties.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ import Test.Framework.Providers.QuickCheck2 (testProperty)
2626
newtype Key = K { unK :: Int }
2727
deriving (Arbitrary, CoArbitrary, Eq, Ord, Read, Show)
2828

29+
instance Hashable Key where
30+
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
31+
2932
instance Function Key where
3033
function = functionMap unK K
3134

32-
instance Hashable Key where
33-
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
35+
-- | Extracts the value of a ternary function.
36+
-- Copied from Test.QuickCheck.Function.applyFun3
37+
applyFun2 :: Fun (a, b) c -> (a -> b -> c)
38+
applyFun2 (Fun _ f) a b = f (a, b)
39+
40+
-- | Extracts the value of a ternary function.
41+
-- Copied from Test.QuickCheck.Function.applyFun3
42+
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
43+
applyFun3 (Fun _ f) a b c = f (a, b, c)
3444

3545
------------------------------------------------------------------------
3646
-- * Properties
@@ -156,11 +166,6 @@ pInsertWith f k =
156166
M.insertWith f' k 1 `eq_` HM.insertWith f' k 1
157167
where f' = curry . apply $ f
158168

159-
-- | Extracts the value of a ternary function.
160-
-- Copied from Test.QuickCheck.Function.applyFun3
161-
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
162-
applyFun3 (Fun _ f) a b c = f (a, b, c)
163-
164169
pInsertWithKey :: Fun (Key, Int, Int) Int -> Key -> [(Key, Int)] -> Bool
165170
pInsertWithKey f k = M.insertWithKey f' k 1 `eq_` HM.insertWithKey f' k 1
166171
where f' = applyFun3 f

tests/Strictness.hs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Test.ChasingBottoms.IsBottom
88
import Test.Framework (Test, defaultMain, testGroup)
99
import Test.Framework.Providers.QuickCheck2 (testProperty)
1010
import Test.QuickCheck (Arbitrary(arbitrary), CoArbitrary, Property, (===), (.&&.))
11-
import Test.QuickCheck.Function
11+
import Test.QuickCheck.Function (Fun(Fun), Function(function), functionMap)
1212
import Test.QuickCheck.Poly (A)
1313
import Data.Maybe (fromMaybe, isJust)
1414
import Control.Arrow (second)
@@ -27,12 +27,12 @@ import qualified Data.HashMap.Strict as HM
2727
newtype Key = K { unK :: Int }
2828
deriving (Arbitrary, CoArbitrary, Eq, Ord, Show)
2929

30-
instance Function Key where
31-
function = functionMap unK K
32-
3330
instance Hashable Key where
3431
hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
3532

33+
instance Function Key where
34+
function = functionMap unK K
35+
3636
instance (Arbitrary k, Arbitrary v, Eq k, Hashable k) =>
3737
Arbitrary (HashMap k v) where
3838
arbitrary = HM.fromList `fmap` arbitrary
@@ -43,6 +43,16 @@ instance Show (Int -> Int) where
4343
instance Show (Int -> Int -> Int) where
4444
show _ = "<function>"
4545

46+
-- | Extracts the value of a ternary function.
47+
-- Copied from Test.QuickCheck.Function.applyFun3
48+
applyFun2 :: Fun (a, b) c -> (a -> b -> c)
49+
applyFun2 (Fun _ f) a b = f (a, b)
50+
51+
-- | Extracts the value of a ternary function.
52+
-- Copied from Test.QuickCheck.Function.applyFun3
53+
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
54+
applyFun3 (Fun _ f) a b c = f (a, b, c)
55+
4656
------------------------------------------------------------------------
4757
-- * Properties
4858

@@ -76,18 +86,13 @@ pInsertValueStrict k m = isBottom $ HM.insert k bottom m
7686

7787
pInsertWithKeyStrict :: Fun (Int, Int) Int -> Int -> HashMap Key Int -> Bool
7888
pInsertWithKeyStrict f v m =
79-
isBottom $ HM.insertWith (curry . apply $ f) bottom v m
89+
isBottom $ HM.insertWith (applyFun2 f) bottom v m
8090

8191
pInsertWithValueStrict :: Fun (Int, Int) Int -> Key -> Int -> HashMap Key Int
8292
-> Bool
8393
pInsertWithValueStrict f k v m
8494
| HM.member k m = isBottom $ HM.insertWith (const2 bottom) k v m
85-
| otherwise = isBottom $ HM.insertWith (curry . apply $ f) k bottom m
86-
87-
-- | Extracts the value of a ternary function.
88-
-- Copied from Test.QuickCheck.Function.applyFun3
89-
applyFun3 :: Fun (a, b, c) d -> (a -> b -> c -> d)
90-
applyFun3 (Fun _ f) a b c = f (a, b, c)
95+
| otherwise = isBottom $ HM.insertWith (applyFun2 f) k bottom m
9196

9297
pInsertWithKeyKeyStrict :: Fun (Key, Int, Int) Int -> Int -> HashMap Key Int -> Bool
9398
pInsertWithKeyKeyStrict f v m =
@@ -149,11 +154,11 @@ pFromListWithValueResultStrict lst comb_lazy calc_good_raw
149154
calc_good Nothing y@(Just _) = cgr Nothing Nothing || cgr Nothing y
150155
calc_good x@(Just _) Nothing = cgr Nothing Nothing || cgr x Nothing
151156
calc_good x y = cgr Nothing Nothing || cgr Nothing y || cgr x Nothing || cgr x y
152-
cgr = curry $ apply calc_good_raw
157+
cgr = applyFun2 calc_good_raw
153158

154159
-- The Maybe A -> Maybe A -> Maybe A that we're after, representing a
155160
-- potentially less total function than comb_lazy
156-
comb x y = apply comb_lazy (x, y) <$ guard (calc_good x y)
161+
comb x y = applyFun2 comb_lazy x y <$ guard (calc_good x y)
157162

158163
-- What we get out of the conversion using fromListWith
159164
real_map = HM.fromListWith real_comb real_list

0 commit comments

Comments
 (0)