-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.cpp
More file actions
56 lines (52 loc) · 1.35 KB
/
test3.cpp
File metadata and controls
56 lines (52 loc) · 1.35 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
#include <iostream>
#include <string>
#include "HashTable.h"
using namespace std;
bool test3() {
HashTable T3(17);
ulint num = static_cast<ulint>(200*T3.size());
for (ulint i=0; i<num; i++) {
T3.insert(i,2*i-1);
}
if (T3.size() < static_cast<size_t>(num)) { cout << "Lost some stored values. - Rehashing is not done correctly." << endl; return false; }
for (ulint i=0; i<num; i++) {
if (T3.getValue(i) != 2*i-1) {
cout << "Integer values are not stored correctly after rehashing." << endl;
return false;
}
}
for (ulint i=0; i<num; i=i+2) {
T3.erase(i);
}
for (ulint i=1; i<num; i=i+2) {
if (T3.getValue(i) != 2*i-1) {
cout << "Integer values are not stored correctly after rehashing." << endl;
return false;
}
}
for (ulint i=0; i<num; i=i+2) {
T3.insert(i,3*i-1);
}
for (ulint i=0; i<num; i++) {
if (i%2) {
if (T3.getValue(i) != 2*i-1) {
cout << "Integer values are not stored correctly after erasing and reinserting." << endl;
return false;
}
} else {
if (T3.getValue(i) != 3*i-1) {
cout << "Integer values are not stored correctly after erasing and reinserting." << endl;
return false;
}
}
}
return true;
}
int main() {
if (!test3()) {
cout << "Test 3 failed." << endl;
return 1;
}
cout << "Test 3 succeeded." << endl;
return 0;
}