test-check

wilkerlucio 2019-01-28T18:10:36.032600Z

hello people, I just like to share something that I done and found cool, its about how to setup complex configurable generators, in my case I did a generator setup for building random EQL queries (its like the datomic pull syntax), the way I done is by sending to generators thenselves a map environment so the user could replace parts of it when is needed, I posted some docs about it here https://github.com/edn-query-language/eql#generation. @gfredericks I would love to know what you think about this approach, its you see as a good pattern or maybe you have a better way to do it, thanks all!

2019-01-28T18:30:05.033100Z

@wilkerlucio what's the arg to those functions that's being ignored?

wilkerlucio 2019-01-28T18:31:54.034200Z

@gfredericks you mean in the default generators? if the arg is ignored it means that generator is not relying on anything that can be customised, usually the leaves in the process, makes sense?

2019-01-28T18:32:27.034700Z

in the examples, you customize things with (fn [_] ...)

wilkerlucio 2019-01-28T18:32:52.035300Z

here you can see some usages of the params

wilkerlucio 2019-01-28T18:33:05.035700Z

in case you wanted to re-use something on the map, you could pull it from that argument

2019-01-28T18:33:53.035900Z

ah I see

2019-01-28T18:34:20.036500Z

I think you could use (constantly ...) instead of (fn [_] ...), which would be "more performant" in a maybe-doesn't-matter sense

2019-01-28T18:34:47.037100Z

depends on if the function gets called multiple times or not

2019-01-28T18:34:52.037400Z

which I can't tell at a glance

wilkerlucio 2019-01-28T18:35:14.038100Z

interesting, I didn't knew constantly was faster, but really this is only used to build the generators, which is a rather quick operation compared to how much takes to run (and you can cache the built generator if needed to)

2019-01-28T18:35:18.038300Z

but the general idea of passing a map of generator options down a whole tree of generators is a really good one I think, and one I've thought about for test.check

wilkerlucio 2019-01-28T18:35:44.038900Z

yeah, I also found that to be a good way to control for depth, it worked quite well

2019-01-28T18:35:45.039100Z

constantly just means that the return value gets created once, compared to a fn where it gets created every time

wilkerlucio 2019-01-28T18:37:28.039500Z

ah, makes sense, so the generator will be only instantiated once per process

wilkerlucio 2019-01-28T18:38:13.040200Z

at same time it would be always instantiated, even if the user doesn't use anything, seems doesn't matter much in the end :man-shrugging:

2019-01-28T18:45:53.040400Z

yep