hello! does anyone know if it is possible to use test.check’s let
generator to create a spec using spec’s with-gen
? basically i am spec’ing a function and one for one of the args i use let
to create the generator. the problem is that it doesn’t work if i try (spec/with-gen a-spec #(tcg/let…))
or (spec/with-gen a-spec (tcg/let…))
. it seems that something is missing to bridge from test.check to spec.
@matheus.emm that first one should work; what happens when you try it?
this is the error that i see:
Error printing return value (ClassCastException) at advent.code.2019.day4/fn$fn (day4.clj:48).
class clojure.test.check.generators.Generator cannot be cast to class clojure.lang.IFn (clojure.test.check.generators.Generator is in unnamed module of loader clojure.lang.DynamicClassLoader @717f07d1; clojure.lang.IFn is in unnamed module of loader 'app')
and this is the function spec:
(spec/fdef repeated-consecutive-digits?
:args (spec/cat
:ds
(spec/with-gen
(spec/coll-of nat-int? :kind vector? :min-count 1)
(fn []
(check.gen/let [n (check.gen/elements #{2 3 4 5 6})
x (check.gen/nat)
d (check.gen/vector-distinct
(check.gen/such-that #(not= % x)
(check.gen/nat))
(- 6 n))
i (check.gen/elements (range (- 6 n)))]
(concat (subvec d 0 i)
(repeat n x)
(subvec d (+ i n))))))))
nothing there looks weird to me
well
maybe the problem is just (<http://check.ge|check.gen/nat)
?>
try removing the parens
hum… let me see.
that is it. 🙂
phew
thanks! and it was an idiot mistake because i used check.gen/nat
correctly to build another generator. 😓