test-check

lvh 2016-08-19T02:03:08.000306Z

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

lvh 2016-08-19T02:04:55.000307Z

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

lvh 2016-08-19T02:04:59.000308Z

or something

2016-08-19T02:10:39.000309Z

um

2016-08-19T02:11:05.000310Z

you just want to generate collections of byte arrays?

2016-08-19T02:11:42.000311Z

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

2016-08-19T02:17:16.000312Z

@lvh

lvh 2016-08-19T02:19:59.000313Z

@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

lvh 2016-08-19T02:20:25.000314Z

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

2016-08-19T02:21:43.000315Z

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

2016-08-19T02:22:13.000316Z

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

2016-08-19T02:22:31.000317Z

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

2016-08-19T02:26:07.000318Z

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

2016-08-19T02:26:18.000319Z

that should give you a uniform distribution

lvh 2016-08-19T02:26:37.000320Z

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

2016-08-19T02:29:02.000321Z

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

lvh 2016-08-19T02:31:27.000322Z

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

lvh 2016-08-19T02:32:21.000323Z

(opaquely, of course :))

2016-08-19T02:33:17.000324Z

ah

lvh 2016-08-19T02:33:18.000325Z

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 🙂