Shrinkable<Array> generate(std::size_t count, const Random &random, int size, const Gen<U> &gen) const { if (count != N) { throw GenerationFailure( "Count must be equal to length of array for std::array"); } return generate(random, size, gen); }
Shrinkable<T> operator()(const Random &random, int size) const { Random r(random); int currentSize = size; for (int tries = 0; tries < 100; tries++) { auto shrinkable = shrinkable::filter(m_gen(r.split(), currentSize), m_predicate); if (shrinkable) { return std::move(*shrinkable); } currentSize++; } throw GenerationFailure( "Gave up trying to generate value satisfying predicate."); }
Gen<T> inRange(T min, T max) { return [=](const Random &random, int size) { if (max <= min) { std::string msg; msg += "Invalid range [" + std::to_string(min); msg += ", " + std::to_string(max) + ")"; throw GenerationFailure(msg); } const auto rangeSize = detail::scaleInteger(static_cast<Random::Number>(max) - static_cast<Random::Number>(min) - 1, size) + 1; const auto value = static_cast<T>((Random(random).next() % rangeSize) + min); assert(value >= min && value < max); return shrinkable::shrinkRecur( value, [=](T x) { return shrink::towards<T>(x, min); }); }; }