added print
This commit is contained in:
@@ -29,7 +29,6 @@ void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4)
|
||||
|
||||
// *********************************************
|
||||
// prototypes
|
||||
void test_simple();
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
|
||||
@@ -67,6 +67,7 @@ std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n)
|
||||
|
||||
|
||||
// get a value
|
||||
@@ -98,4 +99,17 @@ template <>
|
||||
}
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec)
|
||||
{
|
||||
int i = 0;
|
||||
for (typename ft::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it, i++)
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
int main() {
|
||||
|
||||
// VECTOR
|
||||
test_simple();
|
||||
// tests_vector_constructor();
|
||||
// tests_vector_operator_assignation();
|
||||
tests_vector_constructor();
|
||||
tests_vector_operator_assignation();
|
||||
// tests_vector_begin();
|
||||
// tests_vector_end();
|
||||
// tests_vector_rbegin();
|
||||
|
||||
@@ -3,85 +3,50 @@
|
||||
|
||||
#include "tests_utils.hpp"
|
||||
|
||||
//TEST2(test_simple(), "test")
|
||||
TEST(test_simple)
|
||||
TEST(tests_vector_constructor)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
T myints[] = {VAL(16),VAL(2),VAL(77),VAL(29)};
|
||||
ft::vector<T> myvector (myints, myints + sizeof(myints) / sizeof(T) );
|
||||
// constructors used in the same order as described above:
|
||||
ft::vector<T> first; // empty vector of ints
|
||||
ft::vector<T> second (4,VAL(100)); // four ints with value 100
|
||||
ft::vector<T> third (second.begin(),second.end()); // iterating through second
|
||||
ft::vector<T> fourth (third); // a copy of third
|
||||
|
||||
for (typename ft::vector<T>::iterator it = myvector.begin(); it != myvector.end(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
// the iterator constructor can also be used to construct from arrays:
|
||||
T myints[] = {VAL(16),VAL(2),VAL(77),VAL(29)};
|
||||
ft::vector<T> fifth (myints, myints + sizeof(myints) / sizeof(T) );
|
||||
|
||||
PRINT(fifth);
|
||||
}
|
||||
|
||||
TEST(tests_vector_operator_assignation)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
ft::vector<T> foo (3,VAL(0));
|
||||
ft::vector<T> bar (5,VAL(0));
|
||||
|
||||
bar = foo;
|
||||
foo = ft::vector<T>();
|
||||
|
||||
std::cout << "Size of foo: " << int(foo.size()) << '\n';
|
||||
std::cout << "Size of bar: " << int(bar.size()) << '\n';
|
||||
|
||||
|
||||
// title
|
||||
TITLE(more informations)
|
||||
|
||||
std::cout << "foo:\n";
|
||||
PRINT(foo);
|
||||
|
||||
std::cout << "bar:\n";
|
||||
PRINT(bar);
|
||||
}
|
||||
//TEST2END
|
||||
|
||||
/*
|
||||
void tests_vector_constructor()
|
||||
{
|
||||
TEST(vector::vector (constructor))
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
// constructors used in the same order as described above:
|
||||
ft::vector<int> first; // empty vector of ints
|
||||
ft::vector<int> second (4,100); // four ints with value 100
|
||||
ft::vector<int> third (second.begin(),second.end()); // iterating through second
|
||||
ft::vector<int> fourth (third); // a copy of third
|
||||
|
||||
// the iterator constructor can also be used to construct from arrays:
|
||||
int myints[] = {16,2,77,29};
|
||||
ft::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
|
||||
|
||||
std::cout << "The contents of fifth are:";
|
||||
for (ft::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
}
|
||||
TESTEND
|
||||
}
|
||||
|
||||
void tests_vector_operator_assignation()
|
||||
{
|
||||
TEST(vector::=operator)
|
||||
{
|
||||
// title
|
||||
TITLE(cplusplus.com reference)
|
||||
|
||||
ft::vector<int> foo (3,0);
|
||||
ft::vector<int> bar (5,0);
|
||||
|
||||
bar = foo;
|
||||
foo = ft::vector<int>();
|
||||
|
||||
std::cout << "Size of foo: " << int(foo.size()) << '\n';
|
||||
std::cout << "Size of bar: " << int(bar.size()) << '\n';
|
||||
|
||||
|
||||
// title
|
||||
TITLE(more informations)
|
||||
|
||||
int size;
|
||||
|
||||
size = foo.size();
|
||||
std::cout << "foo:\n";
|
||||
for (int i = 0; i < size; i++)
|
||||
std::cout << "[" << i <<"]" << foo[i];
|
||||
std::cout << "\ncapacity: " << foo.capacity() << "\n";
|
||||
|
||||
size = bar.size();
|
||||
std::cout << "bar:\n";
|
||||
for (int i = 0; i < size; i++)
|
||||
std::cout << "[" << i <<"]" << bar[i];
|
||||
std::cout << "\ncapacity: " << bar.capacity() << "\n";
|
||||
|
||||
}
|
||||
TESTEND
|
||||
}
|
||||
|
||||
void tests_vector_begin() {
|
||||
TEST(vector::begin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user