Generating sorted data with test.check

142 Views Asked by At

I'd like to use test.check to generate sorted time series data of the form

[ [timestamp value] [timestamp value] ..]

where the timestamp, value -pairs are in ascending order by the timestamp.

I can easily generate such data in random order with

(gen/tuple timestamp gen/int) where timestamp is e.g. (gen/choose 1412664660 1423419720)

How should I go about generating sorted data?

1

There are 1 best solutions below

0
On BEST ANSWER

So it came to me while brushing my teeth..

When I asked the question I was thinking "one level too low" about the data I want to generate.

(gen/tuple timestamp gen/int) generates individual tuples and my attempts of doing (gen/fmap sort .. ) on them didn't work because it just sorted the contents of the tuples. What I need to generate is vectors of those tuples.. and fmap sort on those of course works:

(def entry (gen/tuple timestamp gen/int))
(def timeseries (gen/fmap sort (gen/vector entry)))