Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. module Test.AtLeastTwoAndUnique (runAtLeastTwoAndUnique) where
  2.  
  3. import Prelude
  4.  
  5. import Data.Array (nub)
  6. import Test.StrongCheck (Arbitrary, arbitrary)
  7. import Test.StrongCheck.Gen (suchThat)
  8. import Data.Tuple (Tuple(..))
  9. import Data.Tuple.Nested (uncurry3)
  10.  
  11. newtype AtLeastTwoAndUnique a = AtLeastTwoAndUnique (Tuple (Tuple a a) (Array a))
  12.  
  13. runAtLeastTwoAndUnique :: forall a. AtLeastTwoAndUnique a -> { fst :: a, snd :: a, xs :: Array a }
  14. runAtLeastTwoAndUnique (AtLeastTwoAndUnique tuple) = (uncurry3 { fst: _, snd: _, xs: _ }) tuple
  15.  
  16. instance arbAtLeastTwoAndUnique :: (Arbitrary a, Ord a, Show a) => Arbitrary (AtLeastTwoAndUnique a) where
  17. arbitrary = AtLeastTwoAndUnique `map` (arbitrary `suchThat` (unique `compose` toArray))
  18. where
  19. unique xs = nub xs `eq` xs
  20. toArray (Tuple (Tuple x1 x2) xs) = x1 : x2 : xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement