Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generator for numeric ranges #48

Open
emil-e opened this issue Jul 28, 2015 · 1 comment
Open

Add generator for numeric ranges #48

emil-e opened this issue Jul 28, 2015 · 1 comment

Comments

@emil-e
Copy link
Owner

emil-e commented Jul 28, 2015

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

@yairchu
Copy link
Contributor

yairchu commented Aug 1, 2021

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)};
            });
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants