What’s the generator equivalent of “repeatedly”? I know return
is constantly
. Use case is: generate nested data structure with random (but no-shrink, because they don’t affect execution) byte arrays
I think the answer is (defn frepeatedly [f] (fmap #(f) (return nil)))
or something
um
you just want to generate collections of byte arrays?
it sounds like you just described (gen/list (gen/no-shrink gen/bytes))
maybe?
@lvh ⇑
@gfredericks: Well, sorta. I want byte arrays of a specific size (they’re cryptographic keys) — I already have a function for doing that, hence the phrasing of the question
I don’t actually care that they’re cryptographically random for these tests, but have a mild preference for just using the same tool
if you don't use test.check's randomness then you won't have the reproducibility you normally have
but if you're convinced it won't affect your tests and don't want to bother reimplementing as a generator, I'd just "generate" that stuff as part of running your test and not in the generator
fixed-length byte arrays wouldn't be hard to implement though
e.g., (gen/fmap byte-array (gen/vector (gen/choose -128 127) 12))
that should give you a uniform distribution
OK, thanks 🙂 For clarity, the value doesn’t matter, but the length does; any byte array that isn’t exactly this length is wrong and won’t work
(gen/return (byte-array (repeat 12 0)))
:P
I do want them to be different; because I’m deriving keys, so seeing the value that got produced (if the inputs are different) tells me what really happened
(opaquely, of course :))
ah
I think I might go with the approach you suggested of just generating them separately; or using test.check to generate steps rather than doing the operations directly 🙂