Exemplo n.º 1
0
bool all(const Shrinkable<T> &shrinkable, Predicate predicate) {
  if (!predicate(shrinkable)) {
    return false;
  }

  return seq::all(shrinkable.shrinks(),
                  [=](const Shrinkable<T> &shrink) {
                    return shrinkable::all(shrink, predicate);
                  });
}
Exemplo n.º 2
0
std::pair<Shrinkable<CaseDescription>, std::vector<std::size_t>>
shrinkTestCase(const Shrinkable<CaseDescription> &shrinkable,
               TestListener &listener) {
  std::vector<std::size_t> path;
  Shrinkable<CaseDescription> best = shrinkable;

  auto shrinks = shrinkable.shrinks();
  std::size_t i = 0;
  while (auto shrink = shrinks.next()) {
    auto caseDescription = shrink->value();
    bool accept = caseDescription.result.type == CaseResult::Type::Failure;
    listener.onShrinkTried(caseDescription, accept);
    if (accept) {
      best = std::move(*shrink);
      shrinks = best.shrinks();
      path.push_back(i);
      i = 0;
    } else {
      i++;
    }
  }

  return std::make_pair(std::move(best), std::move(path));
}
Exemplo n.º 3
0
std::pair<T, int> findLocalMin(const Shrinkable<T> &shrinkable,
                               Predicate pred) {
  std::pair<T, int> result(shrinkable.value(), 0);
  Seq<Shrinkable<T>> shrinks = shrinkable.shrinks();
  Maybe<Shrinkable<T>> shrink;
  while ((shrink = shrinks.next())) {
    T value = shrink->value();
    if (pred(value)) {
      result.first = std::move(value);
      shrinks = shrink->shrinks();
      result.second++;
    }
  }

  return result;
}
Exemplo n.º 4
0
Seq<T> immediateShrinks(const Shrinkable<T> &shrinkable) {
  return seq::map(shrinkable.shrinks(),
                  [](const Shrinkable<T> &shrink) { return shrink.value(); });
}