Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created August 28, 2015 21:17
Show Gist options
  • Save beckyconning/9a583e5b47d4f8af1c29 to your computer and use it in GitHub Desktop.
Save beckyconning/9a583e5b47d4f8af1c29 to your computer and use it in GitHub Desktop.
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