@@ -28,6 +28,8 @@ import qualified Prelude
28
28
29
29
import Data.List (nub ,sort )
30
30
import qualified Data.List as List
31
+ import Data.List.NonEmpty (NonEmpty (.. ))
32
+ import qualified Data.List.NonEmpty as NE
31
33
import qualified Data.Set as Set
32
34
import Test.Tasty
33
35
import Test.Tasty.HUnit
@@ -185,9 +187,13 @@ main = defaultMain $ testGroup "map-properties"
185
187
, testProperty " unionWithKeyMerge" prop_unionWithKeyMerge
186
188
, testProperty " mergeWithKey model" prop_mergeWithKeyModel
187
189
, testProperty " mergeA effects" prop_mergeA_effects
188
- , testProperty " fromAscList" prop_ordered
190
+ , testProperty " fromAscList" prop_fromAscList
191
+ , testProperty " fromAscListWith" prop_fromAscListWith
192
+ , testProperty " fromAscListWithKey" prop_fromAscListWithKey
189
193
, testProperty " fromDistinctAscList" prop_fromDistinctAscList
190
- , testProperty " fromDescList" prop_rev_ordered
194
+ , testProperty " fromDescList" prop_fromDescList
195
+ , testProperty " fromDescListWith" prop_fromDescListWith
196
+ , testProperty " fromDescListWithKey" prop_fromDescListWithKey
191
197
, testProperty " fromDistinctDescList" prop_fromDistinctDescList
192
198
, testProperty " fromList then toList" prop_list
193
199
, testProperty " toDescList" prop_descList
@@ -1272,31 +1278,46 @@ instance Arbitrary WhenMatchedSpec where
1272
1278
1273
1279
----------------------------------------------------------------
1274
1280
1275
- prop_ordered :: Property
1276
- prop_ordered
1277
- = forAll (choose (5 ,100 )) $ \ n ->
1278
- let xs = [(x,() ) | x <- [0 .. n:: Int ]]
1279
- in fromAscList xs == fromList xs
1280
-
1281
- prop_rev_ordered :: Property
1282
- prop_rev_ordered
1283
- = forAll (choose (5 ,100 )) $ \ n ->
1284
- let xs = [(x,() ) | x <- [0 .. n:: Int ]]
1285
- in fromDescList (reverse xs) == fromList xs
1286
-
1287
1281
prop_list :: [Int ] -> Bool
1288
1282
prop_list xs = (sort (nub xs) == [x | (x,() ) <- toList (fromList [(x,() ) | x <- xs])])
1289
1283
1290
1284
prop_descList :: [Int ] -> Bool
1291
1285
prop_descList xs = (reverse (sort (nub xs)) == [x | (x,() ) <- toDescList (fromList [(x,() ) | x <- xs])])
1292
1286
1287
+ prop_fromDescList :: [(Int , A )] -> Property
1288
+ prop_fromDescList kxs =
1289
+ valid t .&&.
1290
+ t === fromList kxs
1291
+ where
1292
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1293
+ t = fromDescList downSortedKxs
1294
+
1295
+ prop_fromDescListWith :: Fun (A , A ) A -> [(Int , A )] -> Property
1296
+ prop_fromDescListWith f kxs =
1297
+ valid t .&&.
1298
+ t === fromListWith (apply2 f) downSortedKxs
1299
+ where
1300
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1301
+ t = fromDescListWith (apply2 f) downSortedKxs
1302
+
1303
+ prop_fromDescListWithKey :: Fun (Int , A , A ) A -> [(Int , A )] -> Property
1304
+ prop_fromDescListWithKey f kxs =
1305
+ valid t .&&.
1306
+ t === fromListWithKey (apply3 f) downSortedKxs
1307
+ where
1308
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1309
+ t = fromDescListWithKey (apply3 f) downSortedKxs
1310
+
1293
1311
prop_fromDistinctDescList :: [(Int , A )] -> Property
1294
- prop_fromDistinctDescList xs =
1312
+ prop_fromDistinctDescList kxs =
1295
1313
valid t .&&.
1296
- toList t === nub_sort_xs
1314
+ toList t === reverse nubDownSortedKxs
1297
1315
where
1298
- t = fromDistinctDescList (reverse nub_sort_xs)
1299
- nub_sort_xs = List. map List. head $ List. groupBy ((==) `on` fst ) $ List. sortBy (comparing fst ) xs
1316
+ nubDownSortedKxs =
1317
+ List. map NE. head $
1318
+ NE. groupBy ((==) `on` fst ) $
1319
+ List. sortBy (comparing (Down . fst )) kxs
1320
+ t = fromDistinctDescList nubDownSortedKxs
1300
1321
1301
1322
prop_ascDescList :: [Int ] -> Bool
1302
1323
prop_ascDescList xs = toAscList m == reverse (toDescList m)
@@ -1309,13 +1330,40 @@ prop_fromList xs
1309
1330
t == List. foldr (uncurry insert) empty (zip xs xs)
1310
1331
where sort_xs = sort xs
1311
1332
1333
+ prop_fromAscList :: [(Int , A )] -> Property
1334
+ prop_fromAscList kxs =
1335
+ valid t .&&.
1336
+ t === fromList sortedKxs
1337
+ where
1338
+ sortedKxs = List. sortBy (comparing fst ) kxs
1339
+ t = fromAscList sortedKxs
1340
+
1341
+ prop_fromAscListWith :: Fun (A , A ) A -> [(Int , A )] -> Property
1342
+ prop_fromAscListWith f kxs =
1343
+ valid t .&&.
1344
+ t === fromListWith (apply2 f) sortedKxs
1345
+ where
1346
+ sortedKxs = List. sortBy (comparing fst ) kxs
1347
+ t = fromAscListWith (apply2 f) sortedKxs
1348
+
1349
+ prop_fromAscListWithKey :: Fun (Int , A , A ) A -> [(Int , A )] -> Property
1350
+ prop_fromAscListWithKey f kxs =
1351
+ valid t .&&.
1352
+ t === fromListWithKey (apply3 f) sortedKxs
1353
+ where
1354
+ sortedKxs = List. sortBy (comparing fst ) kxs
1355
+ t = fromAscListWithKey (apply3 f) sortedKxs
1356
+
1312
1357
prop_fromDistinctAscList :: [(Int , A )] -> Property
1313
- prop_fromDistinctAscList xs =
1358
+ prop_fromDistinctAscList kxs =
1314
1359
valid t .&&.
1315
- toList t === nub_sort_xs
1360
+ toList t === nubSortedKxs
1316
1361
where
1317
- t = fromDistinctAscList nub_sort_xs
1318
- nub_sort_xs = List. map List. head $ List. groupBy ((==) `on` fst ) $ List. sortBy (comparing fst ) xs
1362
+ nubSortedKxs =
1363
+ List. map NE. head $
1364
+ NE. groupBy ((==) `on` fst ) $
1365
+ List. sortBy (comparing fst ) kxs
1366
+ t = fromDistinctAscList nubSortedKxs
1319
1367
1320
1368
----------------------------------------------------------------
1321
1369
0 commit comments