test-check

Ajay 2019-02-11T15:36:41.002Z

hi, is it possible to make a generator from a custom lazy sequence? For practice, I was trying to use test-check to test FizzBuzz problem - I want a generator that returns multiples of 3 but not of 5 or 15

2019-02-11T15:38:49.002700Z

gen/such-that would suffice here for casual use

Ajay 2019-02-11T15:39:31.003100Z

but it gave up when I tried

2019-02-11T15:45:08.003500Z

Give it a higher max-tries, like 100

alexmiller 2019-02-11T15:45:44.003900Z

itโ€™s help to invert your thinking for stuff like this

alexmiller 2019-02-11T15:46:08.004400Z

generate a number, then use fmap to multiply by 3 so you always generate multiples of 3

alexmiller 2019-02-11T15:46:32.005100Z

could then use such-that over that to exclude multiples of 5 if needed

Ajay 2019-02-11T15:47:33.006100Z

Ok I had tried generate a number, then use fmap to multiply by 3 so you always generate multiples of 3 but didn't apply such-that to exclude multiples of 5, let me try, thank you for all replies!

2019-02-11T15:49:38.006500Z

yeah I forgot to say the multiply part

2019-02-11T15:49:59.006900Z

you could still use such-that without multiplying, it'd just be even slower and you'd probable need an even higher max-tries

2019-02-11T15:51:01.007500Z

if you want to be fancy you can use some number theory to generate a good distribution of such numbers w/o filtering

Ajay 2019-02-11T15:58:46.007900Z

could get it to work! thank you!

๐Ÿ‘ 1
alexmiller 2019-02-11T16:00:38.008800Z

you could gen a set of non-5 numbers, then multiply all of them and by 3 to generate only numbers divisible by 3 but not 5 :)

1
2019-02-11T16:01:08.009100Z

@alexmiller that's just moving the filtering to the first generator, right?

alexmiller 2019-02-11T16:02:54.009300Z

yeah

2019-02-11T16:06:17.010300Z

the fancy thing I have in mind is basically (gen/let [fifteens gen/int, threes (gen/choose 1 4)] (+ (* 15 fifteens) (* 3 threes))) I think that'd work