test-check

Matheus Moreira 2020-04-16T12:45:01.031200Z

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.

2020-04-16T13:04:32.032100Z

@matheus.emm that first one should work; what happens when you try it?

Matheus Moreira 2020-04-16T13:05:50.032200Z

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

Matheus Moreira 2020-04-16T13:06:42.032400Z

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

2020-04-16T13:08:39.032600Z

nothing there looks weird to me

2020-04-16T13:09:02.032800Z

well

2020-04-16T13:09:16.033Z

maybe the problem is just (<http://check.ge|check.gen/nat)?>

2020-04-16T13:09:27.033200Z

try removing the parens

Matheus Moreira 2020-04-16T13:09:45.033400Z

hum… let me see.

Matheus Moreira 2020-04-16T13:11:58.033600Z

that is it. 🙂

2020-04-16T13:12:06.033800Z

phew

Matheus Moreira 2020-04-16T13:12:49.034Z

thanks! and it was an idiot mistake because i used check.gen/nat correctly to build another generator. 😓

🙂 1