2

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?

Janne
  • 3,647
  • 7
  • 28
  • 34

1 Answers1

2

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)))
Janne
  • 3,647
  • 7
  • 28
  • 34