@@ -97,8 +97,10 @@ main = defaultMain
97
97
, testProperty " partition" prop_partition
98
98
, testProperty " filter" prop_filter
99
99
, testProperty " sort" prop_sort
100
+ , testProperty " sortStable" prop_sortStable
100
101
, testProperty " sortBy" prop_sortBy
101
102
, testProperty " sortOn" prop_sortOn
103
+ , testProperty " sortOnStable" prop_sortOnStable
102
104
, testProperty " unstableSort" prop_unstableSort
103
105
, testProperty " unstableSortBy" prop_unstableSortBy
104
106
, testProperty " unstableSortOn" prop_unstableSortOn
@@ -560,6 +562,30 @@ prop_sort :: Seq OrdA -> Bool
560
562
prop_sort xs =
561
563
toList' (sort xs) ~= Data.List. sort (toList xs)
562
564
565
+ data UnstableOrd = UnstableOrd
566
+ { ordKey :: OrdA
567
+ , _ignored :: A
568
+ } deriving (Show )
569
+
570
+ instance Eq UnstableOrd where
571
+ x == y = compare x y == EQ
572
+
573
+ instance Ord UnstableOrd where
574
+ compare (UnstableOrd x _) (UnstableOrd y _) = compare x y
575
+
576
+ instance Arbitrary UnstableOrd where
577
+ arbitrary = liftA2 UnstableOrd arbitrary arbitrary
578
+ shrink (UnstableOrd x y) =
579
+ [ UnstableOrd x' y'
580
+ | (x',y') <- shrink (x, y) ]
581
+
582
+ prop_sortStable :: Seq UnstableOrd -> Bool
583
+ prop_sortStable xs =
584
+ (fmap . fmap ) unignore (toList' (sort xs)) ~=
585
+ fmap unignore (Data.List. sort (toList xs))
586
+ where
587
+ unignore (UnstableOrd x y) = (x, y)
588
+
563
589
prop_sortBy :: Seq (OrdA , B ) -> Bool
564
590
prop_sortBy xs =
565
591
toList' (sortBy f xs) ~= Data.List. sortBy f (toList xs)
@@ -575,6 +601,16 @@ prop_sortOn (Fun _ f) xs =
575
601
listSortOn k = Data.List. sortBy (compare `on` k)
576
602
#endif
577
603
604
+ prop_sortOnStable :: Fun A UnstableOrd -> Seq A -> Bool
605
+ prop_sortOnStable (Fun _ f) xs =
606
+ toList' (sortOn f xs) ~= listSortOn f (toList xs)
607
+ where
608
+ #if MIN_VERSION_base(4,8,0)
609
+ listSortOn = Data.List. sortOn
610
+ #else
611
+ listSortOn k = Data.List. sortBy (compare `on` k)
612
+ #endif
613
+
578
614
prop_unstableSort :: Seq OrdA -> Bool
579
615
prop_unstableSort xs =
580
616
toList' (unstableSort xs) ~= Data.List. sort (toList xs)
0 commit comments