#include #include #include #include #include #include #include #include #include #include #include #include #include auto main() -> int { using namespace book_store; using namespace book_store::utility; std::array books; std::array book_titles; std::array members; std::array member_ids; std::mt19937 random_number_generator(std::random_device{}()); utility::random::book_random_engine random(random_number_generator); auto perform = [](std::string_view name, auto action) { std::cout << name << " ..."; action(); std::cout << " ok.\n"; }; perform("populating books and book_titles", [&]() { for (auto [index, book] : std::ranges::views::enumerate(books)) { auto random_title = random.title(); book_titles[static_cast(index)] = random_title; book = product::book{random_title, random.authors(), random.publisher(), random.isbn(), random.price_usd(), random.copy_count()}; } }); perform("verifying all books are present", [&]() { for (const auto &title : book_titles) { if (std::ranges::find(book_titles, title) == book_titles.end()) { clear_cerr(); std::cerr << "error: title not found" << '\n'; std::terminate(); } } }); perform("verifying book copy count increment", [&]() { for (int i = 0; i < 100; ++i) { auto &book = books[std::uniform_int_distribution( 0, books.size() - 1)(random_number_generator)]; auto copy_count = book.copies(); auto random_copy_count = static_cast( std::uniform_int_distribution(0, 100)( random_number_generator)); book.copies(copy_count + random_copy_count); if (book.copies() != copy_count + random_copy_count) { clear_cerr(); std::cerr << "error: invalid copy count after increment" << '\n'; std::terminate(); } } }); perform("populating members and member_ids", [&]() { for (auto [index, member] : std::views::enumerate(members)) { auto random_name = random.name(); auto random_surname = random.name(); auto random_id = random.id(); member_ids[static_cast(index)] = random_id; member = consumer::customer{random_name, random_surname, random_id}; } }); perform("verifying all members are present", [&]() { for (auto member_id : member_ids) { if (std::ranges::find(member_ids, member_id) == member_ids.end()) { std::cerr << "error: id not found" << '\n'; std::terminate(); } } }); return 0; }