-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.cpp
More file actions
111 lines (81 loc) · 2.51 KB
/
sample.cpp
File metadata and controls
111 lines (81 loc) · 2.51 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
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
#include <bits/stdc++.h>
#include "tiered_vector.hpp"
using namespace std;
using namespace cppx;
#define endl '\n';
int main() {
tiered_vector<int> tv;
cout << "-----------START OF TEST-----------" << endl;
cout << endl;
//Push Back:
for (int i = 0; i < 5000; ++i) {
tv.push_back(3 * i);
}
cout << "Size: " << tv.size() << endl;
cout << "Capacity: " << tv.capacity() << endl;
cout << endl;
//Random Access:
cout << "1001th element: " << tv[1000] << endl;
cout << "4001th element: " << tv[4000] << endl;
cout << endl;
//Copy Constructor Check:
tiered_vector<int> copy_tv = tv;
cout << "Copy size: " << copy_tv.size() << endl;
cout << "Copy element check: " << copy_tv[1234] << endl;
cout << endl;
//Move Constructor Check:
tiered_vector<int> move_tv = move(tv);
cout << "Move size: " << move_tv.size() << endl;
cout << "Original after move size(should be 0): " << tv.size() << endl;
cout << endl;
//Resize Smaller
move_tv.resize(2000);
cout << "After resize(2000): " << move_tv.size() << endl;
cout << endl;
//Resize Larger
move_tv.resize(8000);
cout << "After resize(8000): " << move_tv.size() << endl;
cout << endl;
//Assignment Operator test
tiered_vector<int> assigned;
assigned = copy_tv;
cout << "Assigned size: " << assigned.size() << endl;
cout << endl;
//Pop Back hysterisis
cout << "Before pop_back x1000: " << assigned.size() << endl;
for (int i = 0; i < 1000; ++i) {
assigned.pop_back();
}
cout << "After pop_back x1000: " << assigned.size() << endl;
cout << endl;
//Iterator Test
cout << "Iterator Test: " << endl;
tiered_vector<int> iter_tv;
for (int i = 0; i < 20; ++i) {
iter_tv.push_back(i + 1);
}
for (auto it = iter_tv.begin(); it != iter_tv.end(); ++it) {
cout << *it << " ";
}
cout << endl;
for (auto it: iter_tv) {
cout << it << " ";
}
cout << endl;
//Recerse iterator test
cout << "Reverse Iterator Test: " << endl;
for (auto rit = iter_tv.rbegin(); rit != iter_tv.rend(); ++rit) {
cout << *rit << " ";
}
cout << endl;
//sorting test
cout << "Sorting Test: " << endl;
tiered_vector<int> sort_tv = {5, 3, 8, 1, 2, 7, 4, 6};
sort(sort_tv.begin(), sort_tv.end());
for (auto& val : sort_tv) {
cout << val << " ";
}
cout << endl;
cout << "-----------END OF TEST-----------" << endl;
return 0;
}