Fork me on GitHub
#test-check
<
2018-02-08
>
wilkerlucio02:02:12

hello, I'm trying to limit the recursion of a generator, the problem is that the recursion is not "direct", it generates something, that generates something else, and ends up in circle, but this kind of recursion seems to not be detected by test.check recursion limit

wilkerlucio02:02:43

I was thinking about using some dynamic var to track how many times my generator was called, and stop if goes after a number in a call stack

wilkerlucio02:02:23

I was trying something like this:

wilkerlucio02:02:24

(s/def ::query-root
  (s/coll-of ::query-expr-root :kind vector?
    :gen #(if (> *max-depth* 0)
            (binding [*max-depth* (dec *max-depth*)]
              (s/gen (s/coll-of ::query-expr-root :kind vector? :max-count 5)))
            (s/gen #{[]}))))

wilkerlucio02:02:46

but this doesn't work, because the binding is running on the generator definition, and not when the actual gen is running

wilkerlucio02:02:04

I was trying to find a way to wrap some generator with this logic, but can't figure how to hook it up

wilkerlucio02:02:33

how can I make this? because otherwise my generator fail about 80% of the time because of stack overflow =/

gfredericks14:02:58

by "test.check recursion limit" you're referring to the mechanism in clojure.spec that's used when generating generators?

gfredericks14:02:53

have you tried expressing the generator for the whole thing using gen/recursive-gen?