Example #1
0
  static Seq<CommandSequence> shrinkIndividual(const CommandSequence &s) {
    return seq::mapcat(
        seq::range(s.numFixed, s.entries.size()),
        [=](std::size_t i) {
          const auto &preState = s.stateAt(i);
          auto valid =
              seq::filter(s.entries[i].shrinkable.shrinks(),
                          [=](const Shrinkable<CmdSP> &s) {
                            return isValidCommand(*s.value(), preState);
                          });

          return seq::map(std::move(valid),
                          [=](Shrinkable<CmdSP> &&cmd) {
                            auto shrunk = s;
                            auto &entry = shrunk.entries[i];

                            entry.shrinkable = std::move(cmd);
                            entry.postState = shrunk.stateAt(i);
                            entry.shrinkable.value()->apply(entry.postState);
                            shrunk.regenerateEntriesFrom(i + 1);

                            shrunk.numFixed = i;
                            return shrunk;
                          });
        });
  }