An idea. You can make a type:<br><br>data TestContains = TestContains Tweet TweetSet<br><br>and the make an Arbitrary instance for it. When you do<br>a recursove call you have three different tweets one new tweet<br>and two from the sub-calls. Then you can place one of them in the<br>
result. In the end you will have a random TweetSet with some value from it.<br><br>Here is a scratch of the implementation:<br><br>instance Arbitrary TestContains where <br> arbitrary = sized set' <br> where set' 0 = mkSingleTweet <$> (arbitrary :: Tweet)<br>
set' n = do<br> t0 <- arbitrary :: Tweet <br> TestContains t1 ts1 <- subTweets<br> TestContains t2 ts2 <- subTweets<br> t <- oneof [t0, t1, t2] <br>
return $ TestContains t $ TweetSet t0 ts1 ts2<br><br> subTweets = set' (n `div` 2) <br><br><br><div class="gmail_quote">2012/11/21 <span dir="ltr"><<a href="mailto:graham@fatlazycat.com" target="_blank">graham@fatlazycat.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have<br>
<br>
data Tweet = Tweet {<br>
user :: String,<br>
text :: String,<br>
retweets :: Double<br>
} deriving (Show)<br>
<br>
data TweetSet = NoTweets | SomeTweets Tweet TweetSet TweetSet<br>
<br>
and trying to create some generators for testing, with<br>
<br>
instance Arbitrary Tweet where<br>
arbitrary = liftM3 Tweet arbitrary arbitrary arbitrary<br>
<br>
instance Arbitrary TweetSet where<br>
arbitrary = sized set'<br>
where set' 0 = return NoTweets<br>
set' n | n>0 = oneof[return NoTweets, liftM3 SomeTweets<br>
arbitrary subTweets subTweets]<br>
where subTweets = set' (n `div` 2)<br>
<br>
but wondering how I would go about generating a random TweetSet that<br>
contains a known random Tweet I later have reference to and I would also<br>
assume the known Tweet to be placed randomly.<br>
<br>
Then I could test a contains function.<br>
<br>
Thanks<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>