-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestHashTable.cpp
57 lines (47 loc) · 2.04 KB
/
testHashTable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include "HashTable.h"
int main() {
HashTable<int> dict = HashTable<int>(3);
std::cout << dict << std::endl;
std::cout << "dict.capacity(): " << dict.capacity() << std::endl;
std::cout << "dict.entries(): " << dict.entries() << std::endl;
std::cout << std::endl;
std::cout << "dict.insert('One', 1) ..." << std::endl;
dict.insert("One", 1);
std::cout << "dict.insert('Two', 2) ..." << std::endl;
dict.insert("Two", 2);
std::cout << "dict.insert('Three', 3) ..." << std::endl;
dict.insert("Three", 3);
std::cout << "dict.insert('Four', 4) ..." << std::endl;
dict.insert("Four", 4);
std::cout << "dict.insert('Five', 5) ..." << std::endl;
dict.insert("Five", 5);
std::cout << "dict.insert('Six', 6) ..." << std::endl;
dict.insert("Six", 6);
std::cout << std::endl;
std::cout << std::endl << dict << std::endl;
std::cout << "dict.search('One'): " << dict.search("One") << std::endl;
std::cout << "dict['Four']: " << dict["Four"] << std::endl;
std::cout << "dict.remove('Three'): " << dict.remove("Three") << std::endl;
std::cout << std::endl;
std::cout << std::endl << dict << std::endl;
try {
dict.insert("One", 44);
std::cout << "Oooops! dict.insert('One') did not throw std::runtime_error... :(" << std::endl;
} catch (std::runtime_error &e) {
std::cout << "dict.insert('One') => throwed std::runtime_error: " << e.what() << std::endl;
}
try {
dict.search("Ten");
std::cout << "Oooops! dict.search('Ten') did not throw std::runtime_error... :(" << std::endl;
} catch (std::runtime_error &e) {
std::cout << "dict.search('Ten') => throwed std::runtime_error: " << e.what() << std::endl;
}
try {
dict.remove("Ten");
std::cout << "Oooops! dict.remove('Ten') did not throw std::runtime_error... :(" << std::endl;
} catch (std::runtime_error &e) {
std::cout << "dict.remove('Ten') => throwed std::runtime_error: " << e.what() << std::endl;
}
return 0;
}