Skip to content
Advertisement

Generating an interval set in hypothesis

I have some code that works with intervals, which are really just python dicts with the following structure:

JavaScript

Writing a strategy for a single interval is relatively straightforward. I’d like to write a strategy to generate interval sets. An interval set is a list of intervals, such that:

  • The list contains an arbitrary number of intervals.
  • The interval names are unique.
  • The intervals do not overlap.
  • All intervals are contained within the range (0.0, 1.0).
  • Each interval’s size is correct.
  • The intervals do not have to be contiguous and the entire range doesn’t need to be covered.

How would you write this strategy?

Advertisement

Answer

I managed to get this working with the following strategies. This is almost certainly sub-optimal but does produce the desired object state.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement