Fork me on GitHub
#test-check
<
2016-08-19
>
lvh02:08:08

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

lvh02:08:55

I think the answer is (defn frepeatedly [f] (fmap #(f) (return nil)))

lvh02:08:59

or something

gfredericks02:08:05

you just want to generate collections of byte arrays?

gfredericks02:08:42

it sounds like you just described (gen/list (gen/no-shrink gen/bytes)) maybe?

lvh02:08:59

@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

lvh02:08:25

I don’t actually care that they’re cryptographically random for these tests, but have a mild preference for just using the same tool

gfredericks02:08:43

if you don't use test.check's randomness then you won't have the reproducibility you normally have

gfredericks02:08:13

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

gfredericks02:08:31

fixed-length byte arrays wouldn't be hard to implement though

gfredericks02:08:07

e.g., (gen/fmap byte-array (gen/vector (gen/choose -128 127) 12))

gfredericks02:08:18

that should give you a uniform distribution

lvh02:08:37

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

gfredericks02:08:02

(gen/return (byte-array (repeat 12 0))) :P

lvh02:08:27

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

lvh02:08:21

(opaquely, of course :))

lvh02:08:18

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 🙂