reiddraper / simple-check

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

Keyword shrinking #22

Closed si14 closed 11 years ago

si14 commented 11 years ago

Here is a property:

(defspec householder-matrix-props num-tests
  (prop/for-all [impl (gen/elements [:vectorz])
                 v (gen-vector gen/int 5)]
     (prn impl v)))

If obviously fails (prn returns nil). However, it's interesting how this is shrinked:

lein test clojure.core.matrix.properties
:vectorz [0 -1 0 -1 0]
:ectorz [0 -1 0 -1 0]
:ctorz [0 -1 0 -1 0]
:torz [0 -1 0 -1 0]
:orz [0 -1 0 -1 0]
:rz [0 -1 0 -1 0]
:z [0 -1 0 -1 0]
: [0 -1 0 -1 0]
: [-1 0 -1 0]
: [0 -1 0]
: [-1 0]
: [0]
: []
{:test-var householder-matrix-props, :result nil, :failing-size 1, :num-tests 0, :fail [:vectorz [0 -1 0 -1 0]], :shrunk {:total-nodes-visited 12, :depth 11, :smallest [: []]}}

This looks wrong to me.

reiddraper commented 11 years ago

Nice catch. Will try and get a fix in today or tomorrow.

reiddraper commented 11 years ago

Would you expect :vectorz to shrink at all, or just shrink to :z?

si14 commented 11 years ago

I wouldn't expect :vectorz to shrink at all. My intuition is that gen/elements should just choose one of alternatives instead of messing with what's inside.

reiddraper commented 11 years ago

Yeah, this is a tough issue. As far as simple-check is concerned, it just sees the keywords, and uses the shrink protocol to shrink it (dispatching on the keyword type). Need to ponder on this a bit, not sure how the Erlang version does this.

reiddraper commented 11 years ago

I've got a little bit of a lead on how this might work, going to work on a proof-of-concept and see how much of a breaking change it might be.

reiddraper commented 11 years ago

I have a proof-of-concept in the generators-shrink-themselves branch. Assuming this continues to look good, it'll get merged in. This should solve all other issues with information implicitly or explicitly encoded in generators not being respected during shrinking.

reiddraper commented 11 years ago

All tests are passing on this branch now. I'm going to get it cleaned up and then ask for some folks to test it out. It's a big change, but I'm pretty confident it will end up getting merged in.

si14 commented 11 years ago

Awesome! Thank you.