Fork me on GitHub
#test-check
<
2020-04-16
>
Matheus Moreira12:04:01

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.

gfredericks13:04:32

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

Matheus Moreira13:04:50

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 Moreira13:04:42

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

gfredericks13:04:39

nothing there looks weird to me

gfredericks13:04:16

maybe the problem is just (?>

gfredericks13:04:27

try removing the parens

Matheus Moreira13:04:45

hum… let me see.

Matheus Moreira13:04:58

that is it. 🙂

Matheus Moreira13:04:49

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

🙂 4