Fork me on GitHub
#test-check
<
2017-03-06
>
peeja16:03:56

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.

peeja17:03:13

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).

peeja17:03:21

Is my expectation wrong, or is that a bug?

gfredericks17:03:37

@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

gfredericks17:03:46

I think you could call it a half-bug

peeja17:03:51

Yeah, that's what I mean

gfredericks17:03:00

I'd be happy to have a ticket about it if it's a problem for you

gfredericks17:03:07

trying to think of a workaround

peeja17:03:08

Awesome, will do.

gfredericks17:03:03

@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))

gfredericks17:03:21

I would consider making something like that first-class if there was a compelling general need for it

peeja17:03:28

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.

peeja17:03:51

And for the custom seed, thanks, I'll try that!

gfredericks17:03:49

every can't generate an empty collection? that sounds like a spec bug

peeja17:03:36

It can, but I can't force it to

peeja17:03:14

I'd like (gen/generate (s/every string?) 0) to always be empty

gfredericks17:03:42

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

gfredericks18:03:51

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

gfredericks18:03:08

I'm reworking the distribution of gen/large-integer and I think something based on that could work