Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 8579971

Browse files
committed
Merge pull request #41 from purescript/update-tests
Update tests
2 parents aab648f + 524046b commit 8579971

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"purescript-functions": "^0.1.0"
3030
},
3131
"devDependencies": {
32-
"purescript-quickcheck": "^0.7.0"
32+
"purescript-quickcheck": "^0.11.0"
3333
}
3434
}

test/Test/Data/Map.purs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import Test.QuickCheck.Gen (Gen(..))
1515

1616
import qualified Data.Map as M
1717

18-
instance arbMap :: (Eq k, Ord k, Arbitrary k, Arbitrary v) => Arbitrary (M.Map k v) where
19-
arbitrary = M.fromList <$> arbitrary
18+
newtype TestMap k v = TestMap (M.Map k v)
2019

21-
instance arbitraryList :: (Arbitrary a) => Arbitrary (List a) where
22-
arbitrary = toList <$> (arbitrary :: Gen (Array a))
20+
instance arbTestMap :: (Eq k, Ord k, Arbitrary k, Arbitrary v) => Arbitrary (TestMap k v) where
21+
arbitrary = TestMap <<< M.fromList <$> arbitrary
2322

2423
data SmallKey = A | B | C | D | E | F | G | H | I | J
2524

@@ -133,7 +132,7 @@ mapTests = do
133132
<?> ("k1: " ++ show k1 ++ ", v1: " ++ show v1 ++ ", k2: " ++ show k2 ++ ", v2: " ++ show v2)
134133

135134
log "Check balance property"
136-
quickCheck' 5000 $ \instrs ->
135+
quickCheck' 1000 $ \instrs ->
137136
let
138137
tree :: M.Map SmallKey Int
139138
tree = runInstructions instrs M.empty
@@ -146,7 +145,7 @@ mapTests = do
146145
quickCheck $ \k v -> M.lookup (k :: SmallKey) (M.singleton k (v :: Int)) == Just v
147146

148147
log "Random lookup"
149-
quickCheck' 5000 $ \instrs k v ->
148+
quickCheck' 1000 $ \instrs k v ->
150149
let
151150
tree :: M.Map SmallKey Int
152151
tree = M.insert k v (runInstructions instrs M.empty)
@@ -160,7 +159,7 @@ mapTests = do
160159
in f (f arr) == f (arr :: List (Tuple SmallKey Int)) <?> show arr
161160

162161
log "fromList . toList = id"
163-
quickCheck $ \m -> let f m = M.fromList (M.toList m) in
162+
quickCheck $ \(TestMap m) -> let f m = M.fromList (M.toList m) in
164163
M.toList (f m) == M.toList (m :: M.Map SmallKey Int) <?> show m
165164

166165
log "fromListWith const = fromList"
@@ -176,26 +175,27 @@ mapTests = do
176175
M.fromListWith (<>) arr == f (arr :: List (Tuple String String)) <?> show arr
177176

178177
log "Lookup from union"
179-
quickCheck $ \m1 m2 k -> M.lookup (smallKey k) (M.union m1 m2) == (case M.lookup k m1 of
180-
Nothing -> M.lookup k m2
181-
Just v -> Just (number v)) <?> ("m1: " ++ show m1 ++ ", m2: " ++ show m2 ++ ", k: " ++ show k ++ ", v1: " ++ show (M.lookup k m1) ++ ", v2: " ++ show (M.lookup k m2) ++ ", union: " ++ show (M.union m1 m2))
178+
quickCheck $ \(TestMap m1) (TestMap m2) k ->
179+
M.lookup (smallKey k) (M.union m1 m2) == (case M.lookup k m1 of
180+
Nothing -> M.lookup k m2
181+
Just v -> Just (number v)) <?> ("m1: " ++ show m1 ++ ", m2: " ++ show m2 ++ ", k: " ++ show k ++ ", v1: " ++ show (M.lookup k m1) ++ ", v2: " ++ show (M.lookup k m2) ++ ", union: " ++ show (M.union m1 m2))
182182

183183
log "Union is idempotent"
184-
quickCheck $ \m1 m2 -> (m1 `M.union` m2) == ((m1 `M.union` m2) `M.union` (m2 :: M.Map SmallKey Int))
184+
quickCheck $ \(TestMap m1) (TestMap m2) -> (m1 `M.union` m2) == ((m1 `M.union` m2) `M.union` (m2 :: M.Map SmallKey Int))
185185

186186
log "Union prefers left"
187-
quickCheck $ \m1 m2 k -> M.lookup k (M.union m1 (m2 :: M.Map SmallKey Int)) == (M.lookup k m1 <|> M.lookup k m2)
187+
quickCheck $ \(TestMap m1) (TestMap m2) k -> M.lookup k (M.union m1 (m2 :: M.Map SmallKey Int)) == (M.lookup k m1 <|> M.lookup k m2)
188188

189189
log "unionWith"
190190
for_ [Tuple (+) 0, Tuple (*) 1] $ \(Tuple op ident) ->
191-
quickCheck $ \m1 m2 k ->
191+
quickCheck $ \(TestMap m1) (TestMap m2) k ->
192192
let u = M.unionWith op m1 m2 :: M.Map SmallKey Int
193193
in case M.lookup k u of
194194
Nothing -> not (M.member k m1 || M.member k m2)
195195
Just v -> v == op (fromMaybe ident (M.lookup k m1)) (fromMaybe ident (M.lookup k m2))
196196

197197
log "unionWith argument order"
198-
quickCheck $ \m1 m2 k ->
198+
quickCheck $ \(TestMap m1) (TestMap m2) k ->
199199
let u = M.unionWith (-) m1 m2 :: M.Map SmallKey Int
200200
in1 = M.member k m1
201201
v1 = M.lookup k m1

test/Test/Data/StrMap.purs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import Test.QuickCheck.Gen (Gen(..))
1414
import qualified Data.String as S
1515
import qualified Data.StrMap as M
1616

17-
instance arbStrMap :: (Arbitrary v) => Arbitrary (M.StrMap v) where
18-
arbitrary = M.fromList <$> arbitrary
17+
newtype TestStrMap v = TestStrMap (M.StrMap v)
1918

20-
instance arbitraryList :: (Arbitrary a) => Arbitrary (List a) where
21-
arbitrary = toList <$> (arbitrary :: Gen (Array a))
19+
instance arbTestStrMap :: (Arbitrary v) => Arbitrary (TestStrMap v) where
20+
arbitrary = TestStrMap <<< M.fromList <$> arbitrary
2221

2322
data Instruction k v = Insert k v | Delete k
2423

@@ -74,7 +73,7 @@ strMapTests = do
7473
quickCheck $ \k v -> M.lookup k (M.singleton k (v :: Int)) == Just v
7574

7675
log "Random lookup"
77-
quickCheck' 5000 $ \instrs k v ->
76+
quickCheck' 1000 $ \instrs k v ->
7877
let
7978
tree :: M.StrMap Int
8079
tree = M.insert k v (runInstructions instrs M.empty)
@@ -88,8 +87,9 @@ strMapTests = do
8887
in f (f arr) == f (arr :: List (Tuple String Int)) <?> show arr
8988

9089
log "fromList . toList = id"
91-
quickCheck $ \m -> let f m = M.fromList (M.toList m) in
92-
M.toList (f m) == M.toList (m :: M.StrMap Int) <?> show m
90+
quickCheck $ \(TestStrMap m) ->
91+
let f m = M.fromList (M.toList m) in
92+
M.toList (f m) == M.toList (m :: M.StrMap Int) <?> show m
9393

9494
log "fromListWith const = fromList"
9595
quickCheck $ \arr -> M.fromListWith const arr ==
@@ -104,12 +104,14 @@ strMapTests = do
104104
M.fromListWith (<>) arr == f (arr :: List (Tuple String String)) <?> show arr
105105

106106
log "Lookup from union"
107-
quickCheck $ \m1 m2 k -> M.lookup k (M.union m1 m2) == (case M.lookup k m1 of
108-
Nothing -> M.lookup k m2
109-
Just v -> Just (number v)) <?> ("m1: " ++ show m1 ++ ", m2: " ++ show m2 ++ ", k: " ++ show k ++ ", v1: " ++ show (M.lookup k m1) ++ ", v2: " ++ show (M.lookup k m2) ++ ", union: " ++ show (M.union m1 m2))
107+
quickCheck $ \(TestStrMap m1) (TestStrMap m2) k ->
108+
M.lookup k (M.union m1 m2) == (case M.lookup k m1 of
109+
Nothing -> M.lookup k m2
110+
Just v -> Just (number v)) <?> ("m1: " ++ show m1 ++ ", m2: " ++ show m2 ++ ", k: " ++ show k ++ ", v1: " ++ show (M.lookup k m1) ++ ", v2: " ++ show (M.lookup k m2) ++ ", union: " ++ show (M.union m1 m2))
110111

111112
log "Union is idempotent"
112-
quickCheck $ \m1 m2 -> (m1 `M.union` m2) == ((m1 `M.union` m2) `M.union` (m2 :: M.StrMap Int)) <?> (show (M.size (m1 `M.union` m2)) ++ " != " ++ show (M.size ((m1 `M.union` m2) `M.union` m2)))
113+
quickCheck $ \(TestStrMap m1) (TestStrMap m2) ->
114+
(m1 `M.union` m2) == ((m1 `M.union` m2) `M.union` (m2 :: M.StrMap Int)) <?> (show (M.size (m1 `M.union` m2)) ++ " != " ++ show (M.size ((m1 `M.union` m2) `M.union` m2)))
113115

114116
log "toList = zip keys values"
115-
quickCheck $ \m -> M.toList m == zipWith Tuple (toList $ M.keys m) (M.values m :: List Int)
117+
quickCheck $ \(TestStrMap m) -> M.toList m == zipWith Tuple (toList $ M.keys m) (M.values m :: List Int)

0 commit comments

Comments
 (0)