Ejemplo n.º 1
0
int main(int argc, char **argv) {
  std::random_device randomDevice; // used for seeding
  std::default_random_engine generator(randomDevice());
  std::uniform_int_distribution<unsigned> distribution(0,RandomSpread);

  Tester tester;

  if (argc < 0) tester.dump(); // force this to be used

  auto next = [&] { return distribution(generator); };

  llvm::SmallString<128> key;

  while (true) {
    auto operation = next();

    // Add elements to key.
    if (operation <= .15 * RandomSpread) {
      unsigned n = next() % 1 ? 5 : 7;
      for (unsigned i = 0; i != n; ++i)
        key.push_back('a' + (next() % 26));

    // Remove elements from key.
    } else if (operation <= .3 * RandomSpread) {
      unsigned n = next() % 1 ? 5 : 7;
      for (unsigned i = 0; i != n; ++i)
        if (!key.empty()) key.pop_back();

    // Insert.
    } else if (operation <= .7 * RandomSpread) {
      unsigned value = next();
      llvm::outs() << "  tester.insert(\"" << key << "\", " << value << ");\n";
      tester.insert(key, value);

    // Find.
    } else if (operation <= .98 * RandomSpread) {
      llvm::outs() << "  tester.find(\"" << key << "\");\n";
      tester.find(key);

    // Clear.
    } else {
      llvm::outs() << "  tester.clear();\n";
      tester.clear();
    }

    llvm::outs() << "  tester.validate();\n";
    tester.validate();
  }
}