/* * dictionary_tests.cpp * * Created on: 09.01.2013 * Author: trifon */ #include "list_dictionary.cpp" #include "tree_dictionary.cpp" #include "hashtable.cpp" #include "test.h" typedef TreeDictionary<> TestDictionary; bool createTest() { TestDictionary d; return true; } bool addTest() { TestDictionary d; d.add(3, 30); d.add(1, 10); d.add(5, 50); d.add(2, 20); // d.print(); // d.keys().print(); // d.values().print(); return d.search(4) == NULL && *d.search(2) == 20; } bool removeTest() { TestDictionary d; d.add(3, 30); d.add(1, 10); d.add(5, 50); d.add(2, 20); if (d.remove(4) || !d.remove(3)) return false; return d.search(3) == NULL && *d.search(2) == 20; } const int TEST_NUMBER = 3; Test tests[] = { { "createTest", createTest }, { "addTest", addTest }, { "removeTest", removeTest } }; typedef LinkedHashTable<> TestHash; void hashTest() { StringKey sk1 = "Milena"; StringKey sk2 = "Miglena"; cout << sk1.hashCode() << ' ' << sk2.hashCode() << endl; TestHash ht; ht.add("Petar", 40235); ht.add("Kaloyan", 40888); ht.add("Milena", 40212); ht.add("Miglena", 40208); cout << *ht.search("Petar") << endl; cout << *ht.search("Kaloyan") << endl; cout << *ht.search("Milena") << endl; cout << *ht.search("Miglena") << endl; if (ht.search("Lyuben") == NULL) cout << "Lyuben not found\n"; ht.remove("Milena"); if (ht.search("Milena") == NULL) cout << "Milena not found\n"; cout << *ht.search("Miglena") << endl; } int main() { // runTests(tests, TEST_NUMBER); hashTest(); return 0; }