forked from CS-PCC/CS3A_Assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_test.cpp
executable file
·179 lines (143 loc) · 4.96 KB
/
basic_test.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "gtest/gtest.h"
#include <cmath>
#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <list>
//------------------------------------------------------------------------------
//Files we are testing:
#include "../../includes/vector/my_vector.h"
//------------------------------------------------------------------------------
using namespace std;
//------------------------------------------------------------------------------
// COPY BASIC_TEST INTO THIS FILE.
// AND THEN,
// DO NOT EDIT THIS FILE ANY FURTHER
//------------------------------------------------------------------------------
bool test_vector(bool debug = false){
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Vector<int> v;
Vector<int> v1(a, 10);
v = v1;
cout << v << endl;
v[0] = 100;
cout << v << endl;
v.at(1) = 101;
cout << v << endl;
v.front() = 1000;
v.back() = 99;
cout << v << endl;
v.pop_back();
v.pop_back();
cout << v << endl;
v.push_back(10);
cout << v << endl;
v.insert(3, 300);
cout << v << endl;
v.erase(5);
cout << v << endl;
cout << "9 is at index: [" << v.index_of(9) << "]" << endl;
cout << "300 is at index: [" << v.index_of(300) << "]" << endl;
cout << "at index: 5: " << v.at(5) << endl;
cout << "at index: 8: " << v[8] << endl;
cout << "vector size is now: " << v.size() << endl;
cout << "vector capacity is now: " << v.capacity() << endl;
v.resize(14, 66);
cout << "vector capacity is now: " << v.capacity() << endl << endl;
cout << v << endl;
v.resize(11);
cout << v << endl;
v.resize(13, 88);
cout << v << endl;
v.reserve(16);
cout << v << endl;
v.push_back(14);
cout << v << endl;
v.push_back(15);
cout << v << endl;
v.push_back(16);
cout << v << endl;
v.push_back(17);
cout << v << endl;
v.pop_back();
v.pop_back();
v.pop_back();
v.pop_back();
cout << v << endl;
v.pop_back();
v.pop_back();
v.pop_back();
v.pop_back();
v.pop_back();
cout << v << endl;
cout << "vector is empty: " << boolalpha << v.empty() << endl;
cout << "vector size is now: " << v.size() << endl;
cout << "vector capacity is now: " << v.capacity() << endl;
cout << "\n\n-------- D O N E -------------\n" << endl;
return true;
}
//Lord help me!
bool debug = false;
TEST(TEST_BASIC_TEST, BasicTest)
{
bool success = test_vector(debug);
EXPECT_EQ(success, true);
}
int main(int argc, char **argv) {
if (argc>1){
debug = argv[1][0]=='t';
}
::testing::InitGoogleTest(&argc, argv);
std::cout<<"\n\n----------running basic_test.cpp---------\n\n"<<std::endl;
return RUN_ALL_TESTS();
}
/*
includes
├── add_entry
│ └── add_entry.h
├── array_functions
│ └── array_functions.h
└── vector
└── my_vector.h
----------running basic_test.cpp---------
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TEST_BASIC_TEST
[ RUN ] TEST_BASIC_TEST.BasicTest
(10/10) [ 0 1 2 3 4 5 6 7 8 9 ]
(10/10) [ 100 1 2 3 4 5 6 7 8 9 ]
(10/10) [ 100 101 2 3 4 5 6 7 8 9 ]
(10/10) [ 1000 101 2 3 4 5 6 7 8 99 ]
( 8/10) [ 1000 101 2 3 4 5 6 7 ]
( 9/10) [ 1000 101 2 3 4 5 6 7 10 ]
(10/10) [ 1000 101 2 300 3 4 5 6 7 10 ]
( 9/10) [ 1000 101 2 300 3 5 6 7 10 ]
9 is at index: [-1]
300 is at index: [3]
at index: 5: 5
at index: 8: 10
vector size is now: 9
vector capacity is now: 10
vector capacity is now: 14
(14/14) [ 1000 101 2 300 3 5 6 7 10 66 66 66 66 66 ]
(11/14) [ 1000 101 2 300 3 5 6 7 10 66 66 ]
(13/14) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 ]
(13/16) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 ]
(14/16) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 14 ]
(15/16) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 14 15 ]
(16/16) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 14 15 16 ]
(17/32) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 14 15 16 17 ]
(13/32) [ 1000 101 2 300 3 5 6 7 10 66 66 88 88 ]
( 8/16) [ 1000 101 2 300 3 5 6 7 ]
vector is empty: false
vector size is now: 8
vector capacity is now: 16
-------- D O N E -------------
[ OK ] TEST_BASIC_TEST.BasicTest (0 ms)
[----------] 1 test from TEST_BASIC_TEST (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (1 ms total)
[ PASSED ] 1 test.
➜ build git:(master) ✗
*/