reiddraper / simple-check

QuickCheck for Clojure
http://reiddraper.github.io/simple-check/
286 stars 18 forks source link

Implicitly bind properties given to for-all #47

Closed hypirion closed 10 years ago

hypirion commented 10 years ago

Whenever I need two properties, one of them which depends on the other, and I want to use both property results within a for-all, I feel the code gets unnecessary cluttered.

As an example, let's say I want to create vectors with integers with some upper boundary, n. To check my specific property, I need to pass in n and the vector generated like so:

(prop/for-all
    [[n vect] (gen/bind gen/s-pos-int
                (fn [n] (gen/tuple
                          (gen/return n)
                          (gen/vector (gen/choose 0 n)))))]
  (check property using n and vect here))

It would be convenient if we could implicitly bind generated values in successive generators, for example like this:

(prop/for-all [n gen/s-pos-int
               vect (gen/vector (gen/choose 0 n))]
  (check property using n and vect here))

I would guess there's some rationale for not doing this (the distinction between values and generators probably), but it would be lovely to have a more succinct way of expressing such a use case. Perhaps there's some feature I've not yet found which solves this problem?

May be related to #10 in some way.

reiddraper commented 10 years ago

Your understanding is correct, and my thought now is that #10 is the solution to this. Within a single for-all 'list of bindings', I'd like to keep the distinction between values and generators, but using nested generators will let you express this in a cleaner way than using bind manually. I don't have an ETA on the feature, but it's of high importance to me.

hypirion commented 10 years ago

@reiddraper, ah, alright. Considering you are aware of the problem and have thought of a solution to it, I'll close this and follow that issue instead.