Skip to content

Commit 9854de3

Browse files
committed
Use QuickCheck's 'Fun' when testing insertWith and insertWithKey.
We use apply instead of apply2 and apply3 because the latter two are only available in recent QuickCheck versions. We also use (Int, Int, Int) -> Int for the function for insertWithKey so we don't need to add additional instances to Key to work with `Fun`.
1 parent acac434 commit 9854de3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tests/HashMapProperties.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import qualified Data.HashMap.Lazy as HM
1818
#endif
1919
import qualified Data.Map as M
2020
import Test.QuickCheck (Arbitrary, Property, (==>), (===))
21+
import Test.QuickCheck.Function (Fun, apply)
2122
import Test.Framework (Test, defaultMain, testGroup)
2223
import Test.Framework.Providers.QuickCheck2 (testProperty)
2324

@@ -147,12 +148,14 @@ pDeleteCollision k1 k2 k3 idx = (k1 /= k2) && (k2 /= k3) && (k1 /= k3) ==>
147148
| which == 2 = k1
148149
| otherwise = error "Impossible"
149150

150-
pInsertWith :: Key -> [(Key, Int)] -> Bool
151-
pInsertWith k = M.insertWith (+) k 1 `eq_` HM.insertWith (+) k 1
151+
pInsertWith :: Fun (Int, Int) Int -> Key -> [(Key, Int)] -> Bool
152+
pInsertWith f k =
153+
M.insertWith f' k 1 `eq_` HM.insertWith f' k 1
154+
where f' = curry . apply $ f
152155

153-
pInsertWithKey :: Key -> [(Key, Int)] -> Bool
154-
pInsertWithKey k = M.insertWithKey f k 1 `eq_` HM.insertWithKey f k 1
155-
where f (K k') a b = if k' >= 0 then a else b
156+
pInsertWithKey :: Fun (Int, Int, Int) Int -> Key -> [(Key, Int)] -> Bool
157+
pInsertWithKey f k = M.insertWithKey f' k 1 `eq_` HM.insertWithKey f' k 1
158+
where f' k' v1 v2 = apply f (unK k', v1, v2)
156159

157160
pAdjust :: Key -> [(Key, Int)] -> Bool
158161
pAdjust k = M.adjust succ k `eq_` HM.adjust succ k

0 commit comments

Comments
 (0)