Is there any way to generate a value (or a sequence of values) from a generator using a custom seed? It looks to me like the only place you can set the seed (that's a public interface) is in quick-check
itself.
It looks like gen/vector
with a min/max length ignores size
. That is, I expected (gen/generate (gen/vector gen/string 0 10) 0)
to generate an empty vector, but it doesn't (any more often than it would with no size
given).
Is my expectation wrong, or is that a bug?
@peeja ignores size when picking the vector size, probably; it doesn't ignore size entirely since it'll use it when generating elements from the passed-in generator
I think you could call it a half-bug
Yeah, that's what I mean
I'd be happy to have a ticket about it if it's a problem for you
trying to think of a workaround
Awesome, will do.
@peeja w.r.t. custom seeds, you'd have to resort to not-quite-public-API calls such as (rose/root (gen/call-gen g (random/make-random seed) size))
I would consider making something like that first-class if there was a compelling general need for it
In my case, I'm trying to determine whether a keyword's spec specifies a sequence or not by generating the simplest (cheapest) value I can and asking if it's sequential?
. clojure.spec/every
's generator uses a max/min even if you don't give it one, which means I'm always generating elements. Generating an empty vector/list would be better, but it's not a dealbreaker, considering the size still keeps the complexity of what it generates pretty low.
And for the custom seed, thanks, I'll try that!
every
can't generate an empty collection? that sounds like a spec bug
It can, but I can't force it to
I'd like (gen/generate (s/every string?) 0)
to always be empty
Oh I see. Spec does some manual sizing that I'm not sure is justified in every case, and this might be an example of that
the question of a better distribution for gen/vector
is interesting, since users could say something like (gen/vector g 0 40000)
and it'd seem weird to only give them relatively small vectors
I'm reworking the distribution of gen/large-integer
and I think something based on that could work