hedgehogqa / r-hedgehog

Release with confidence, state-of-the-art property testing for R.
Other
54 stars 5 forks source link

Clarification of concepts #8

Open lionel- opened 6 years ago

lionel- commented 6 years ago

"shrink" is not defined in the README which makes it harder for newcomers to understand the package.

It seems that there are two big aspects in the package, generation of data and iteration over data. Also monads and currying seem to play a role. (Altough it seems what you're calling currying is just argument application). It is a bit nebulous how these aspects work (independently and together).

In general I think any solution involving monads and currying is not going to feel R-like so it /might/ be worth exploring other approaches, if possible at all. See also the flowery package for some experiments on iterators as R functions, which perhaps is relevant https://github.com/lionel-/flowery.

HuwCampbell commented 6 years ago

Hi.

Shrink has the usual meaning, just to make smaller. Quickcheck style libraries is build up large random values for testing. Without shrinking them it can be quite hard to interpret what's actually causing the bug, as the signal to noise ration can be high. Shrinking allows one to see the most pertinent causes of bugs.

As for gens being monads, if one isn't aware of the concept they shouldn't worry too much. I'm just stating that one can make a generator using the output of another generator.

Thanks for the heads up about flowery. I appreciate your iterate function's handling of quasi for loops for this purpose; it's interesting (and kind of insane in its implementation), but seems to provide something clean for the end user.

HuwCampbell commented 6 years ago

I have managed to port over a function which acts similarly.

gen_squares   <- generate(for (i in gen.int(10)) i^2)
gen_sq_digits <- generate(for (i in gen_squares) {
  gen.c(of = i, gen.element(1:9))
})

which is kind of cool.

Edit: I would note, it's actually just sugar on and_then.