#include "Ware.h" #include "hashTable.h" #include #include // Function to generate random strings for our Wares. See: // https://stackoverflow.com/a/12468109 std::string random_string(size_t length) { auto randchar = []() -> char { const char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; const size_t max_index = (sizeof(charset) - 1); return charset[rand() % max_index]; }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); return str; } int main() { HashTable ht; // Insert 100 random Wares for (int i = 0; i < 100; i++) { ht.insert(new Ware(random_string(5), 123, 2.0, 2.0, 2.0)); } // Insert 2 additional ones with known Names ht.insert(new Ware("Testware", 123, 2.0, 2.0, 2.0)); ht.insert(new Ware("Foo", 123, 2.0, 2.0, 2.0)); ht.print(); // Search for one that should exist and print it. const Ware *s1 = ht.search("Testware"); std::cout << *s1 << std::endl; // Delete the Ware we found bool test = ht.deleteItem("Testware"); std::cout << test << std::endl; // Try to delete a Ware which does not exist. bool test2 = ht.deleteItem("Bar"); std::cout << test2 << std::endl; }