-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strictness tests for left and right folds
* Add new tests and update existing tests to check against lists. This covers all left and right folds on Set, Map, IntSet, IntMap. * Remove the now unnecessary nothunks dependency.
- Loading branch information
Showing
9 changed files
with
399 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Utils.NubSorted | ||
( | ||
-- NubSorted and NubSortedOnFst | ||
NubSorted(..) | ||
, NubSortedOnFst(..) | ||
) where | ||
|
||
import qualified Data.List as List | ||
import qualified Data.List.NonEmpty as NonEmpty | ||
import Data.Ord (comparing) | ||
import Test.QuickCheck | ||
|
||
newtype NubSorted a = NubSorted { getNubSorted :: [a] } | ||
deriving Show | ||
|
||
instance (Ord a, Arbitrary a) => Arbitrary (NubSorted a) where | ||
arbitrary = NubSorted . nubSortBy compare <$> arbitrary | ||
shrink = map (NubSorted . nubSortBy compare) . shrink . getNubSorted | ||
|
||
newtype NubSortedOnFst a b = NubSortedOnFst { getNubSortedOnFst :: [(a, b)] } | ||
deriving Show | ||
|
||
instance (Ord a, Arbitrary a, Arbitrary b) | ||
=> Arbitrary (NubSortedOnFst a b) where | ||
arbitrary = NubSortedOnFst . nubSortBy (comparing fst) <$> arbitrary | ||
shrink = | ||
map (NubSortedOnFst . nubSortBy (comparing fst)) . | ||
shrink . | ||
getNubSortedOnFst | ||
|
||
nubSortBy :: (a -> a -> Ordering) -> [a] -> [a] | ||
nubSortBy cmp = | ||
map NonEmpty.head . | ||
NonEmpty.groupBy (\x y -> cmp x y == EQ) . | ||
List.sortBy cmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.