DS 2556 homework 5

Testing code for simple_hash [code lang=c++] #include #include #include #include "simple_hash.h" //#include <unordered_map>

bool test1() { CP::unordered_mapstd::string,std::string mymap;

std::cout << "size = " << mymap.size() << std::endl; std::cout << "load_factor = " << mymap.load_factor() << std::endl;

mymap["Bakery"]="Barbara"; // new element inserted mymap["Seafood"]="Lisa"; // new element inserted mymap["Produce"]="John"; // new element inserted

std::string name = mymap["Bakery"]; // existing element accessed (read) mymap["Seafood"] = name; // existing element accessed (written)

mymap["Bakery"] = mymap["Produce"]; // existing elements accessed (read/written)

name = mymap["Deli"]; // non-existing element: new element "Deli" inserted!

mymap["Produce"] = mymap["Gifts"]; // new element "Gifts" inserted, "Produce" written mymap["Gifts"] = "AAA";

mymap.print();

mymap.insert(std::make_pair("Test1","Test2")); mymap.print();

return true; }

bool test2() { CP::unordered_mapstd::string,int mymap;

mymap["somchai"] = 1; mymap["nattee"] = 2; mymap["vishnu"] = 4; mymap["nuttapong"] = 20;

mymap.erase("nuttapong"); mymap.erase("attawith"); mymap.erase("athasit");

mymap.print(); std::cout << mymap.contain("nuttapong") << std::endl; std::cout << mymap.contain("somchai") << std::endl; return true; }

int main() {

if (test1()) std::cout << "-------------------- TEST 1 OK -------------------" << std::endl; if (test2()) std::cout << "-------------------- TEST 2 OK -------------------" << std::endl;

}

[/code]