message: tests.files.cpp:create_directory_tree -- change magic numbers to names
diff: @@ -93,23 +93,45 @@ namespace UnitTest1
  std::random_device rd;
  constexpr std::uint64_t max_depth = 5;
  constexpr std::uint64_t width = 5;
  - const auto type = depth < max_depth ? uid{0, 9}(urbg) : uid{7, 9}(urbg);
  - // 0 <= type < 7 : directory
  - // 7 = type : regular
  - // 8 = type : regular symlink (regular file if !ALLOW_SYMLINKS)
  - // 9 = type : directory symlink (^^)
  + // we want ~70% of our "files" to be directories, and then a third
  + // each of the remaining ~30% to be regular files, directory symlinks,
  + // and regular symlinks
  + constexpr std::uint64_t directory_min_tag = 0;
  + constexpr std::uint64_t directory_max_tag = 6;
  + constexpr std::uint64_t regular_file_tag = 7;
  + constexpr std::uint64_t regular_symlink_tag = 8;
  + constexpr std::uint64_t directory_symlink_tag = 9;
  +
  + // if we're at the max depth, we only want to build non-directories
  + std::uint64_t file_type;
  + if (depth < max_depth) {
  + file_type = uid{directory_min_tag, regular_symlink_tag}(urbg);
  + } else {
  + file_type = uid{regular_file_tag, regular_symlink_tag}(urbg);
  + }
  +
  + if (!ALLOW_SYMLINKS && file_type > regular_file_tag) {
  + file_type = regular_file_tag;
  + }
  std::error_code ec;
  - if (type >= 7)
  + if (type <= directory_max_tag)
  {
  - // I don't want to move urbg forward conditionally
  - if (type == 7 || !ALLOW_SYMLINKS)
  + fs.create_directory(base, ec);
  + Assert::IsFalse(bool(ec));
  +
  + for (int i = 0; i < width; ++i)
  + {
  + create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
  + }
  + }
  + else if (type == regular_file_tag)
  {
  // regular file
  fs.write_contents(base, "", ec);
  }
  - else if (type == 8)
  + else if (type == regular_symlink_tag)
  {
  // regular symlink
  fs.write_contents(base, "", ec);
  @@ -119,7 +141,7 @@ namespace UnitTest1
  basep_link.replace_filename(basep.filename().native() + L"-link");
  std::filesystem::create_symlink(basep, basep_link, ec);
  }
  - else
  + else // type == directory_symlink_tag
  {
  // directory symlink
  std::filesystem::path basep = base.native();
  @@ -127,21 +149,6 @@ namespace UnitTest1
  }
  Assert::IsFalse(bool(ec));
  -
  - }
  - else
  - {
  - // directory
  - fs.create_directory(base, ec);
  - Assert::IsFalse(bool(ec));
  -
  - for (int i = 0; i < width; ++i)
  - {
  - create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
  - }
  -
  - }
  -
  }
  };
  }
  