Fork me on GitHub
#clojure-spec
<
2017-09-11
>
bfabry18:09:26

@samedhi well... they're not equivalent, because a optional key is different to a required key which is a (possibly empty) map. it seems like the generator produced by map-of just doesn't produce empty maps often enough to avoid blowing the stack

bfabry18:09:22

you need to be able to reference something before it's defined in order to support recursive specs, which is an intended feature

samedhi18:09:32

Hmm, interesting. It appears that I am referring to ::posts from within ::post before ::posts actually exist…

bfabry18:09:11

yes, that's intended to be supported

bfabry18:09:20

I don't know enough about how generators work, I'm guessing it's more sophisticated than just random so that's why it's managing to find the pathological case of a very deeply nested tree every time

tbaldridge20:09:01

Yes, a lot of the complexity in generators comes from the feature of shrinking. When you get a test failure with a generator, test.check will try to shrink the possible data set to give you the smallest failing test. So instead of giving you "Failure when I tried: [123123121 55 3 9 5 23 4]" It may say: "Failure when I tried: [0 2]". And that tells you a lot about went wrong:

tbaldridge20:09:44

for example you know that the vector has to be at least two items long (it didn't fail when there was only one value in the vector). And that the second number has to be larger than one: (since 0 and 1 didn't cause it to fail).

tbaldridge20:09:14

That sort of information is very helpful in debugging, but requires a lot of backtracking in the generator, and that's what makes them so hard to write/understand.

bfabry23:09:29

I would love to know the "right" way to make the generators work for the recursive structure above