test-check

peeja 2017-03-06T16:17:56.000246Z

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.

peeja 2017-03-06T17:11:13.000247Z

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

peeja 2017-03-06T17:11:21.000248Z

Is my expectation wrong, or is that a bug?

2017-03-06T17:18:37.000249Z

@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

2017-03-06T17:18:46.000250Z

I think you could call it a half-bug

peeja 2017-03-06T17:18:51.000251Z

Yeah, that's what I mean

2017-03-06T17:19:00.000252Z

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

2017-03-06T17:19:07.000253Z

trying to think of a workaround

peeja 2017-03-06T17:19:08.000254Z

Awesome, will do.

2017-03-06T17:20:03.000255Z

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

2017-03-06T17:20:21.000256Z

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

peeja 2017-03-06T17:22:28.000257Z

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.

peeja 2017-03-06T17:22:51.000258Z

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

2017-03-06T17:23:49.000259Z

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

peeja 2017-03-06T17:25:36.000260Z

It can, but I can't force it to

peeja 2017-03-06T17:26:14.000261Z

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

2017-03-06T17:30:42.000262Z

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

2017-03-06T18:58:51.000263Z

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

2017-03-06T18:59:08.000264Z

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