コード例 #1
0
ファイル: Container.hpp プロジェクト: pereckerdal/rapidcheck
 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);
 }
コード例 #2
0
ファイル: Predicate.hpp プロジェクト: Christewart/rapidcheck
  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.");
  }
コード例 #3
0
ファイル: Numeric.hpp プロジェクト: pereckerdal/rapidcheck
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); });
  };
}