-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_vector.cpp
142 lines (118 loc) · 4.53 KB
/
main_vector.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "inc/Vector.hpp"
#include <iostream> // for testing
#include <vector> // for testing
int main(void)
{
std::cout << "======= TESTING CTORS =======" << std::endl;
/* DEFAULT CTOR */
std::cout << "TESTING DEFAULT CTOR" << std::endl
<< std::endl;
std::vector<int> a;
ft::vector<int> b;
std::cout << &a[0] << std::endl;
std::cout << &b[0] << std::endl;
std::cout << std::endl;
/* FILL CTOR */
std::cout << "TESTING FILL CTOR" << std::endl
<< std::endl;
int i = 12;
std::vector<int> c(3, i);
ft::vector<int> d(3, i);
std::cout << std::endl;
std::cout << std::endl;
std::cout << "Original vector :" << std::endl;
std::cout << c[0] << std::endl;
std::cout << c[1] << std::endl;
std::cout << c[2] << std::endl;
std::cout << c[3] << std::endl; // random val
std::cout << "Size : " << c.size() << std::endl;
std::cout << std::endl;
std::cout << "My vector :" << std::endl;
std::cout << d[0] << std::endl;
std::cout << d[1] << std::endl;
std::cout << d[2] << std::endl;
std::cout << d[3] << std::endl; // random val
std::cout << "Size : " << d.size() << std::endl;
std::cout << std::endl;
std::cout << "TESTING COPY CTOR" << std::endl << std::endl;
ft::vector<int> e(d);
std::vector<int> f(c);
std::cout << f[0] << std::endl;
std::cout << f[1] << std::endl;
std::cout << f[2] << std::endl;
std::cout << f[3] << std::endl; // random val
std::cout << "Size : " << f.size() << std::endl;
/* COPY CTOR */
// std::cout << "TESTING COPY CTOR" << std::endl << std::endl;
// ft::vector<int> g(d); // lacks the end(), get_allocator() methods
// std::cout << g[0] << std::endl;
// std::cout << g[1] << std::endl; // random value from non initialized memory
std::cout << "======= TESTING OPERATORS =======" << std::endl << std::endl;
std::cout << "======= TESTING ITERATORS =======" << std::endl << std::endl;
//create a vector w/ different numbers inside
/* METHODS */
std::cout << "======= TESTING METHODS =======" << std::endl << std::endl;
std::cout << "TESTING MAX_SIZE()" << std::endl << std::endl;
std::cout << "OG vec max size : " << a.max_size() << std::endl;
std::cout << "My vec max size : " << b.max_size() << std::endl;
std::cout << "TESTING POP_BACK()" << std::endl << std::endl;
std::cout << "Before :" << std::endl;
std::cout << "My vec size : " << d.size() << std::endl;
std::cout << "OG vec size : " << f.size() << std::endl;
for (size_t i = 0; i < d.size(); i++)
std::cout << d[i] << std::endl;
std::cout << "OG :" << std::endl;
for (size_t i = 0; i < f.size(); i++)
std::cout << f[i] << std::endl;
d.pop_back();
f.pop_back();
std::cout << std::endl;
std::cout << "After :" << std::endl;
for (size_t i = 0; i < d.size(); i++)
std::cout << d[i] << std::endl;
std::cout << "OG :" << std::endl;
for (size_t i = 0; i < f.size(); i++)
std::cout << f[i] << std::endl;
//did it change _end ????
std::cout << std::endl;
std::cout << "My vec size : " << d.size() << std::endl;
std::cout << "OG vec size : " << f.size() << std::endl;
std::cout << std::endl;
std::cout << "TESTING CAPACITY()" << std::endl << std::endl;
std::cout << "OG vec capacity : " << f.capacity() << std::endl;
std::cout << "My vec capacity : " << d.capacity() << std::endl;
std::cout << std::endl;
std::cout << "TESTING RESERVE()" << std::endl << std::endl;
d.reserve(7);
f.reserve(7);
std::cout << "OG vec capacity : " << f.capacity() << std::endl;
std::cout << "My vec capacity : " << d.capacity() << std::endl;
std::cout << std::endl;
std::cout << "TESTING CLEAR()" << std::endl << std::endl;
std::cout << "My vec size b4 clear : " << d.size() << std::endl;
std::cout << "OG vec size b4 clear : " << f.size() << std::endl;
d.clear();
f.clear();
std::cout << "My vec size after clear : " << d.size() << std::endl;
std::cout << "OG vec size after clear : " << f.size() << std::endl;
std::cout << std::endl;
std::cout << "TESTING RESIZE()" << std::endl << std::endl;
std::cout << "Before, my vec :" << std::endl;
for (size_t i = 0; i < d.size(); i++)
std::cout << d[i] << std::endl;
std::cout << "OG :" << std::endl;
for (size_t i = 0; i < f.size(); i++)
std::cout << f[i] << std::endl;
d.resize(9, 1);
f.resize(9, 1);
std::cout << std::endl;
std::cout << "My vec size after resize : " << d.size() << std::endl;
std::cout << "OG vec size after resize : " << f.size() << std::endl;
std::cout << "After :" << std::endl;
for (size_t i = 0; i < d.size(); i++)
std::cout << d[i] << std::endl;
std::cout << "OG :" << std::endl;
for (size_t i = 0; i < f.size(); i++)
std::cout << f[i] << std::endl;
std::cout << std::endl;
}