Closed cstorey closed 11 years ago
Nice observation. This is something I thought about a bit, and (somewhat arbitrarily) chose not to do. But I think I'm changing my mind. Fortunately, I think the change is pretty simple, and you can play around with this function to get you going:
(defn one-of-shrink
[coll]
(gen/bind (gen/choose 0 (dec (count coll)))
(partial nth coll)))
Let me know if this works out, and I'll probably replace the current one-of
implementation with this.
Thanks! That seems to do exactly what I want. I did make a vague attempt to figure out how to do it myself, but I sadly couldn't quite see the wood for the trees, as it were.
Also, I just wanted to say a more general thanks for your hard work on the project, the shrinking functionality is very much appreciated.
You're quite welcome, happy to hear you're finding it useful.
ps., this is now included in 0.5.1
I'm using simple-check to test some parser-combinators, using simple-check to generate some random parsers, and I'm using one-of to choose between a series of parsers, like so:
So Ideally, if a check for a certain parser fails, I'd like it to re-try the same check with a "simpler" parser, so the shrinking order would be something like
(re/literal :z) → (re/literal :a) → (re/epsilon) → (re/zero)
.However, that doesn't seem to be the case. Looking at the rose-tree representations, one-of seems to choose a sub-generator and then delegate the shrinking entirely to that generator. So, for example:
I'd hoped to see a shrinking order of something like:
:bar → :foo → true → false
here. Would that make sense, do you think?