test-check

ghadi 2018-06-26T17:49:55.000363Z

What's the most idiomatic way to make a generator from a source function (like a constructor)?

ghadi 2018-06-26T18:19:49.000300Z

(gen/fmap (fn [f] (f)) (gen/return some-constructor))
Seems oblique to say fmap "apply thyself"

2018-06-26T18:26:05.000291Z

that example might be too simple to express your problem, because you can rewrite it as (gen/return (some-constructor))

2018-06-26T18:26:14.000515Z

unless the constructor is nondeterministic

ghadi 2018-06-26T18:26:28.000680Z

I want to generate fresh instances

ghadi 2018-06-26T18:26:48.000404Z

(the constructor returns a reify)

2018-06-26T18:26:55.000278Z

is this with spec?

ghadi 2018-06-26T18:27:32.000353Z

yes

2018-06-26T18:28:06.000338Z

in general it's not idiomatic in test.check to be generating non-values, so spec exposes a bit of a mismatch here

2018-06-26T18:28:18.000873Z

but I suppose I've heard similar things from alex about spec

2018-06-26T18:29:19.000046Z

so due to all that, there's not a more idiomatic way to do what you're doing

2018-06-26T18:29:49.000819Z

you might even have to be careful about the same instance getting reused during shrinking

2018-06-26T18:30:17.000366Z

I'm 87% sure that's what would happen if you compose this with other generators

ghadi 2018-06-26T18:31:33.000116Z

Interesting.... Thanks Gary

2018-06-26T18:33:20.000073Z

👍 this might be an interesting thing to point out in the spec channel