[Haskell-cafe] QuickCheck Generators

graham at fatlazycat.com graham at fatlazycat.com
Tue Nov 20 22:07:37 CET 2012

I have 

data Tweet = Tweet {
    user :: String,
    text :: String,
    retweets :: Double
    } deriving (Show)

data TweetSet = NoTweets | SomeTweets Tweet TweetSet TweetSet

and trying to create some generators for testing, with

instance Arbitrary Tweet where
  arbitrary = liftM3 Tweet arbitrary arbitrary arbitrary 
instance Arbitrary TweetSet where
  arbitrary = sized set'
    where set' 0 = return NoTweets
          set' n | n>0 = oneof[return NoTweets, liftM3 SomeTweets
          arbitrary subTweets subTweets]
            where subTweets = set' (n `div` 2) 

but wondering how I would go about generating a random TweetSet that
contains a known random Tweet I later have reference to and I would also
assume the known Tweet to be placed randomly.

Then I could test a contains function.


More information about the Haskell-Cafe mailing list