@@ -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
@@ -1271,31 +1277,46 @@ instance Arbitrary WhenMatchedSpec where
1271
1277
1272
1278
----------------------------------------------------------------
1273
1279
1274
- prop_ordered :: Property
1275
- prop_ordered
1276
- = forAll (choose (5 ,100 )) $ \ n ->
1277
- let xs = [(x,() ) | x <- [0 .. n:: Int ]]
1278
- in fromAscList xs == fromList xs
1279
-
1280
- prop_rev_ordered :: Property
1281
- prop_rev_ordered
1282
- = forAll (choose (5 ,100 )) $ \ n ->
1283
- let xs = [(x,() ) | x <- [0 .. n:: Int ]]
1284
- in fromDescList (reverse xs) == fromList xs
1285
-
1286
1280
prop_list :: [Int ] -> Bool
1287
1281
prop_list xs = (sort (nub xs) == [x | (x,() ) <- toList (fromList [(x,() ) | x <- xs])])
1288
1282
1289
1283
prop_descList :: [Int ] -> Bool
1290
1284
prop_descList xs = (reverse (sort (nub xs)) == [x | (x,() ) <- toDescList (fromList [(x,() ) | x <- xs])])
1291
1285
1286
+ prop_fromDescList :: [(Int , A )] -> Property
1287
+ prop_fromDescList kxs =
1288
+ valid t .&&.
1289
+ t === fromList kxs
1290
+ where
1291
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1292
+ t = fromDescList downSortedKxs
1293
+
1294
+ prop_fromDescListWith :: Fun (A , A ) A -> [(Int , A )] -> Property
1295
+ prop_fromDescListWith f kxs =
1296
+ valid t .&&.
1297
+ t === fromListWith (apply2 f) downSortedKxs
1298
+ where
1299
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1300
+ t = fromDescListWith (apply2 f) downSortedKxs
1301
+
1302
+ prop_fromDescListWithKey :: Fun (Int , A , A ) A -> [(Int , A )] -> Property
1303
+ prop_fromDescListWithKey f kxs =
1304
+ valid t .&&.
1305
+ t === fromListWithKey (apply3 f) downSortedKxs
1306
+ where
1307
+ downSortedKxs = List. sortBy (comparing (Down . fst )) kxs
1308
+ t = fromDescListWithKey (apply3 f) downSortedKxs
1309
+
1292
1310
prop_fromDistinctDescList :: [(Int , A )] -> Property
1293
- prop_fromDistinctDescList xs =
1311
+ prop_fromDistinctDescList kxs =
1294
1312
valid t .&&.
1295
- toList t === nub_sort_xs
1313
+ toList t === reverse nubDownSortedKxs
1296
1314
where
1297
- t = fromDistinctDescList (reverse nub_sort_xs)
1298
- nub_sort_xs = List. map List. head $ List. groupBy ((==) `on` fst ) $ List. sortBy (comparing fst ) xs
1315
+ nubDownSortedKxs =
1316
+ List. map NE. head $
1317
+ NE. groupBy ((==) `on` fst ) $
1318
+ List. sortBy (comparing (Down . fst )) kxs
1319
+ t = fromDistinctDescList nubDownSortedKxs
1299
1320
1300
1321
prop_ascDescList :: [Int ] -> Bool
1301
1322
prop_ascDescList xs = toAscList m == reverse (toDescList m)
@@ -1308,13 +1329,40 @@ prop_fromList xs
1308
1329
t == List. foldr (uncurry insert) empty (zip xs xs)
1309
1330
where sort_xs = sort xs
1310
1331
1332
+ prop_fromAscList :: [(Int , A )] -> Property
1333
+ prop_fromAscList kxs =
1334
+ valid t .&&.
1335
+ t === fromList sortedKxs
1336
+ where
1337
+ sortedKxs = List. sortBy (comparing fst ) kxs
1338
+ t = fromAscList sortedKxs
1339
+
1340
+ prop_fromAscListWith :: Fun (A , A ) A -> [(Int , A )] -> Property
1341
+ prop_fromAscListWith f kxs =
1342
+ valid t .&&.
1343
+ t === fromListWith (apply2 f) sortedKxs
1344
+ where
1345
+ sortedKxs = List. sortBy (comparing fst ) kxs
1346
+ t = fromAscListWith (apply2 f) sortedKxs
1347
+
1348
+ prop_fromAscListWithKey :: Fun (Int , A , A ) A -> [(Int , A )] -> Property
1349
+ prop_fromAscListWithKey f kxs =
1350
+ valid t .&&.
1351
+ t === fromListWithKey (apply3 f) sortedKxs
1352
+ where
1353
+ sortedKxs = List. sortBy (comparing fst ) kxs
1354
+ t = fromAscListWithKey (apply3 f) sortedKxs
1355
+
1311
1356
prop_fromDistinctAscList :: [(Int , A )] -> Property
1312
- prop_fromDistinctAscList xs =
1357
+ prop_fromDistinctAscList kxs =
1313
1358
valid t .&&.
1314
- toList t === nub_sort_xs
1359
+ toList t === nubSortedKxs
1315
1360
where
1316
- t = fromDistinctAscList nub_sort_xs
1317
- nub_sort_xs = List. map List. head $ List. groupBy ((==) `on` fst ) $ List. sortBy (comparing fst ) xs
1361
+ nubSortedKxs =
1362
+ List. map NE. head $
1363
+ NE. groupBy ((==) `on` fst ) $
1364
+ List. sortBy (comparing fst ) kxs
1365
+ t = fromDistinctAscList nubSortedKxs
1318
1366
1319
1367
----------------------------------------------------------------
1320
1368
0 commit comments