Whoops, forgot the group on this.

On 27 July 2015 at 18:10, Carlo Zancanaro <carlozancan...@gmail.com> wrote:

> You're generating two random things: the map, and the subset of the keys.
> You can't generate the subset of the keys without first knowing the full
> set of keys, so bind lets you make the subset generator depend on the
> result of the map generator.
>
> I should also point out that shrinking isn't the only problem with your
> original function. Normally in test.check you can repeat a test case by
> providing a seed to the generator. With your original code it would be more
> difficult to repeat a test case.
> On 27/07/2015 5:14 pm, "Mayank Jain" <firesof...@gmail.com> wrote:
>
>>
>> It also might be helpful to know that there is already a subset generator
>>> available in this library
>>> <https://github.com/gfredericks/test.chuck#generators>.
>>>
>>
>> Thanks, this looks good, will check it out.
>>
>>
>>> What you've done here might appear to work, but it will get you into
>>>> trouble when test.check starts to shrink your inputs. When test.check runs
>>>> your generators it relies you you using it as your only source of
>>>> randomness, and so your use of `rand-int` will cause some problems.
>>>>
>>>>
>> Ah yes, I didn't think of shrinking.
>> Thanks a lot for your help! :)
>>
>>
>>
>>> The trick is to use the `bind` function to make a generator which
>>>> depends on the value of another generator (in this case, to capture the
>>>> generated map so you can call rand-subset with the correct set of keys):
>>>>
>>>
>>
>>  I didn't get why I had to use a bind here. What if I had only used fmap?
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to