Clojurians
# test-check

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

lvh 05:03: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

lvh 05:04:55

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

lvh 05:04:59

or something

gfredericks 05:11:05

you just want to generate collections of byte arrays?

gfredericks 05:11:42

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

lvh 05:19: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

lvh 05:20: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

gfredericks 05:21:43

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

gfredericks 05:22: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

gfredericks 05:22:31

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

gfredericks 05:26:07

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

gfredericks 05:26:18

that should give you a uniform distribution

lvh 05:26:37

OK, thanks :slightly_smiling_face: 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

gfredericks 05:29:02

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

lvh 05:31: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

lvh 05:32:21

(opaquely, of course :))

lvh 05:33: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 :slightly_smiling_face: