-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
120 lines (78 loc) · 2.92 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <cassert>
#include "ADS_set.h"
int main() {
// Create an ADS_set instance
ADS_set<int> data_structure;
// Test insertion
data_structure.insert(10);
auto result = data_structure.insert(20);
assert(result.second == true);
assert(data_structure.size() == 2);
result = data_structure.insert(10);
// should be false, element 10 already exists
// and Size still 2
assert(result.second == false);
assert(data_structure.size() == 2);
// Test finding elements
auto it = data_structure.find(10);
assert(it != data_structure.end());
it = data_structure.find(30);
// should not be able to find 30
assert(it == data_structure.end());
// Test erasing elements
size_t erased = data_structure.erase(10);
assert(erased == 1);
// size should be 1
assert(data_structure.size() == 1);
erased = data_structure.erase(30);
// Should have erased 0 elements and still size 1
assert(erased == 0);
assert(data_structure.size() == 1);
// Test clear
data_structure.clear();
// size should be zero now after clearance
assert(data_structure.size() == 0);
// Test inserting from initializer list & Size should be 5
data_structure.insert({1, 2, 3, 4, 5});
assert(data_structure.size() == 5);
// Test copy constructor
ADS_set<int> data_structure_copy(data_structure);
assert(data_structure_copy.size() == 5);
// Test assignment operator
ADS_set<int> data_structure_assign;
data_structure_assign = data_structure;
assert(data_structure_assign.size() == 5); // Size should be 5
// Test swap
ADS_set<int> data_structure_swap;
data_structure_swap.insert({6, 7, 8});
assert(data_structure_swap.size() == 3);
swap(data_structure, data_structure_swap);
assert(data_structure.size() == 3);
assert(data_structure_swap.size() == 5);
// Test iterator
std::cout << "Data structure set contains: ";
for (const auto &elem : data_structure) {
std::cout << elem << " ";
}
std::cout << std::endl;
// Dump the set's internal state for debugging
data_structure.dump();
// Test inserting a large amount of data
const int large_test_size = 1000000;
ADS_set<int> large_data_structure;
for (int i = 0; i < large_test_size; ++i) {
large_data_structure.insert(i);
}
// Verify the large set size
assert(large_data_structure.size() == large_test_size);
// Verify some elements in the large set
// Should find element 0
assert(large_data_structure.find(0) != large_data_structure.end());
// find the middle element
assert(large_data_structure.find(large_test_size / 2) != large_data_structure.end());
// find the last element
assert(large_data_structure.find(large_test_size - 1) != large_data_structure.end());
std::cout << "All tests passed!" << std::endl;
return 0;
}