diff --git a/headers/tests_proto.hpp b/headers/tests_proto.hpp index c4ab59f..7e9631b 100644 --- a/headers/tests_proto.hpp +++ b/headers/tests_proto.hpp @@ -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(); diff --git a/headers/tests_utils.hpp b/headers/tests_utils.hpp index f89add3..6c59cad 100644 --- a/headers/tests_utils.hpp +++ b/headers/tests_utils.hpp @@ -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(n) +# define PRINT(n) print_vector(n) // get a value @@ -98,4 +99,17 @@ template <> } +// get a value +// ********************************************* +template +void print_vector(ft::vector vec) +{ + int i = 0; + for (typename ft::vector::iterator it = vec.begin(); it != vec.end(); ++it, i++) + std::cout << "[" << i << "]" << *it << " "; + std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n"; +} + + #endif + diff --git a/tests/main.cpp b/tests/main.cpp index 03ce661..6426b6d 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -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(); diff --git a/tests/tests_vectors.cpp b/tests/tests_vectors.cpp index e5b1a48..32efaec 100644 --- a/tests/tests_vectors.cpp +++ b/tests/tests_vectors.cpp @@ -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 myvector (myints, myints + sizeof(myints) / sizeof(T) ); + // constructors used in the same order as described above: + ft::vector first; // empty vector of ints + ft::vector second (4,VAL(100)); // four ints with value 100 + ft::vector third (second.begin(),second.end()); // iterating through second + ft::vector fourth (third); // a copy of third - for (typename ft::vector::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 fifth (myints, myints + sizeof(myints) / sizeof(T) ); + + PRINT(fifth); +} + +TEST(tests_vector_operator_assignation) +{ + // title + TITLE(cplusplus.com reference) + + ft::vector foo (3,VAL(0)); + ft::vector bar (5,VAL(0)); + + bar = foo; + foo = ft::vector(); + + 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 first; // empty vector of ints - ft::vector second (4,100); // four ints with value 100 - ft::vector third (second.begin(),second.end()); // iterating through second - ft::vector 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 fifth (myints, myints + sizeof(myints) / sizeof(int) ); - - std::cout << "The contents of fifth are:"; - for (ft::vector::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 foo (3,0); - ft::vector bar (5,0); - - bar = foo; - foo = ft::vector(); - - 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) {