Created
August 28, 2015 21:17
-
-
Save beckyconning/9a583e5b47d4f8af1c29 to your computer and use it in GitHub Desktop.
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
module Test.AtLeastTwoAndUnique (runAtLeastTwoAndUnique) where | |
import Prelude | |
import Data.Array (nub) | |
import Test.StrongCheck (Arbitrary, arbitrary) | |
import Test.StrongCheck.Gen (suchThat) | |
import Data.Tuple (Tuple(..)) | |
import Data.Tuple.Nested (uncurry3) | |
newtype AtLeastTwoAndUnique a = AtLeastTwoAndUnique (Tuple (Tuple a a) (Array a)) | |
runAtLeastTwoAndUnique :: forall a. AtLeastTwoAndUnique a -> { fst :: a, snd :: a, xs :: Array a } | |
runAtLeastTwoAndUnique (AtLeastTwoAndUnique tuple) = (uncurry3 { fst: _, snd: _, xs: _ }) tuple | |
instance arbAtLeastTwoAndUnique :: (Arbitrary a, Ord a, Show a) => Arbitrary (AtLeastTwoAndUnique a) where | |
arbitrary = AtLeastTwoAndUnique `map` (arbitrary `suchThat` (unique `compose` toArray)) | |
where | |
unique xs = nub xs `eq` xs | |
toArray (Tuple (Tuple x1 x2) xs) = x1 : x2 : xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment