-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (56 loc) · 1.37 KB
/
Copy pathmain.cpp
File metadata and controls
67 lines (56 loc) · 1.37 KB
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
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include "array_list.h"
#include "hash_map.h"
using namespace std;
#ifdef assert
#undef assert
#endif
#define assert(check, err) \
if (!check) \
{ \
std::cerr << (err); \
exit(1); \
}
void tests() {
hash_map<string, int> order(20, 0.7);
for (int i = 0; i <= 100; i++)
{
string s(1 + i / 26, (char)(i%26+'A'));
assert(!order.contains(s), "HashMap must not have key " + s );
order[s] = i;
assert(order.contains(s), "HashMap must have key " + s );
}
for (int i = 100; i >= 0; i--)
{
string s(1 + i / 26, (char)(i%26+'A'));
assert(order.contains(s), "HashMap must have key " + s );
assert(order[s] == i, "HashMap key " + s + " must correspond to value");
order.erase(s);
assert(!order.contains(s), "HashMap must not have key " + s );
}
}
struct myclass
{
string operator()() {
return "myclass";
}
~myclass()
{
cout << "Self destruct\n";
}
};
int main()
{
tests();
array_list<myclass> v { myclass {}};
cout << "About to destruct\n";
v.clear();
array_list<int> list { 1, 2, 3, 4 };
for (int i = 5; i <= 100; i++)
list.push_back(i);
list.clear();
for (int i = 0; i < list.size(); i++)
cout << list[i] << " ";
return 0;
}