rapidcheck icon indicating copy to clipboard operation
rapidcheck copied to clipboard

Add generator for numeric ranges

Open emil-e opened this issue 10 years ago • 1 comments

Possibly generating an std::pair of begin/end indexes or begin/size. Think of some clever shrinking heuristics as well.

emil-e avatar Jul 28 '15 14:07 emil-e

This is what I've been using along with JUCE's Ranges:

template <typename T>
struct rc::Arbitrary<juce::Range<T>>
{
    static Gen<juce::Range<T>> arbitrary()
    {
        using Tup = std::tuple<T, T>;
        return gen::map (
            gen::suchThat (gen::arbitrary<Tup>(), [] (Tup t) { return std::get<0> (t) <= std::get<1> (t); }),
            [] (Tup t) {
                return juce::Range<T> {std::get<0> (t), std::get<1> (t)};
            });
    }
};

yairchu avatar Aug 01 '21 07:08 yairchu