Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <ctime>
- #include <map>
- using namespace std;
- vector<string> dictionary = {"how", "like", "how", "like", "a", "winter", "hath", "my", "absence", "been",
- "from", "thee", "the", "pleasure", "of", "the", "fleeting", "year",
- "what", "freezings", "have", "I", "felt,", "what", "dark", "days", "seen!", "what", "old",
- "decembers", "bareness", "every", "where",
- "and", "yet", "this", "time", "removed", "was", "summers", "time",
- "the", "teeming", "autumn", "big", "with", "rich", "increase",
- "bearing", "the", "wanton", "burthen", "of", "the", "prime",
- "like", "widowed", "wombs", "after", "their", "lords", "decease",
- "yet", "this", "abundant", "issue", "seem'd", "to", "me",
- "but", "hope", "of", "orphans,", "and", "unfathered", "fruit",
- "for", "summer", "and", "his", "pleasures", "wait", "on", "thee",
- "and", "thou", "away,", "the", "very", "birds", "are", "mute",
- "or", "if", "they", "sing,", "'tis", "with", "so", "dull", "a", "cheer",
- "that", "leaves", "look", "pale,", "dreading", "the", "winter's", "near",
- "a", "winter", "hath", "my", "absence", "been",
- "what", "freezings", "have", "I", "felt,", "what", "dark", "days", "seen!",
- "what", "old", "December's", "bareness", "every", "where",
- "and", "yet", "this", "time", "removed", "was", "summer's", "time",
- "the", "teeming", "autumn", "big", "with", "rich", "increase",
- "bearing", "the", "wanton", "burthen", "of", "the", "prime",
- "like", "widowed", "wombs", "after", "their", "lords", "decease",
- "yet", "this", "abundant", "issue", "seem'd", "to", "me",
- "but", "hope", "of", "orphans,", "and", "unfathered", "fruit",
- "for", "summer", "and", "his", "pleasures", "wait", "on", "thee",
- "and", "thou", "away,", "the", "very", "birds", "are", "mute",
- "or", "if", "they", "sing,", "'tis", "with", "so", "dull", "a", "cheer",
- "that", "leaves", "look", "pale,", "dreading", "the", "winter's", "near"};
- bool add_map(string key, map<string, bool> &table) {
- if (table[key] != true) {
- table[key] = true;//added
- return true;
- } else {
- return false;
- }
- }
- bool find_in_map(string key, map<string, bool> &table) {
- return table[key] == true;
- }
- bool delete_from_map(string key, map<string, bool> &table) {
- if (table[key] == true) {
- table[key] = false;//deleted
- return true;
- } else {
- return false;
- }
- }
- string random_command() {
- string str;
- size_t sign = rand() % 2;
- str += sign == 0 ? "+" : sign == 1 ? "-" : "?";
- return str;
- }
- string random_string() {
- size_t dictionary_size = dictionary.size();
- size_t num = rand() % dictionary_size;
- num = num == 0 ? 1 : num;
- string str = dictionary[num];
- return str;
- }
- void stress_test(int n_iter) {
- for(int k = 0; k< n_iter;++k) {
- cout << "STRESS No " << n_iter;
- //hash_table *table = new hash_table; - создаешь свою табличку
- map<string, bool> map_table;
- string key;
- string command;
- bool map_res = false;
- bool hash_res = false;
- int num_of_words = rand() % 15 + 1; // вместо 15 - любое удобное число
- for (int i = 0; i < num_of_words; ++i) {
- command = random_command();
- key = random_string();
- cout << "Input : " << command + " " + key << endl;
- hash_res = command == "+" ? /*функция добавления элемента*/(key) : command == "?" ? /*поиска*/(key)
- : /*удаления*/(key); //функции возвращают bool
- map_res = command == "+" ? add_map(key, map_table) : command == "?" ? find_in_map(key, map_table)
- : delete_from_map(key, map_table);
- if (hash_res != map_res) {
- cout << "ASSERT TEST FAILED" << endl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment