tests multi types
This commit is contained in:
3
Makefile
3
Makefile
@@ -55,7 +55,8 @@ SRCS = main.cpp \
|
||||
|
||||
D_HEADERS = ./headers
|
||||
HEADERS = colors.h \
|
||||
tests.hpp \
|
||||
tests_utils.hpp \
|
||||
tests_proto.hpp \
|
||||
\
|
||||
enable_if.hpp \
|
||||
iterator_traits.hpp \
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
#ifndef TESTS_HPP
|
||||
# define TESTS_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "colors.h"
|
||||
#include <vector>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <map> // std::map
|
||||
|
||||
|
||||
// *************************
|
||||
// toogle between test ft and stl
|
||||
#ifdef STL
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************
|
||||
// adding each test to the list
|
||||
# define TEST(s) \
|
||||
{\
|
||||
test_title = #s;\
|
||||
struct tester : public test_base {\
|
||||
void func()
|
||||
# define TESTEND \
|
||||
};\
|
||||
test = new(tester);\
|
||||
test->title = test_title;\
|
||||
test_list.push_back(test);\
|
||||
}
|
||||
|
||||
|
||||
// *******************************
|
||||
// vector of functions test
|
||||
struct test_base { std::string title; virtual void func(){} };
|
||||
extern std::vector<test_base *> test_list;
|
||||
extern test_base *test;
|
||||
extern std::string test_title;
|
||||
|
||||
|
||||
// *************************************
|
||||
// defines for titles
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
|
||||
|
||||
// ***************************************
|
||||
// struct for tests
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 1) {_val = new int[1]; _val[0] = data;}
|
||||
~mystruct() {delete[] _val;}
|
||||
int * get_data() const {return _val;}
|
||||
private:
|
||||
int * _val;
|
||||
};
|
||||
extern std::ostream & operator<<(std::ostream & o, mystruct const & rhs);
|
||||
|
||||
|
||||
// *********************************************
|
||||
// prototypes
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
void tests_vector_end();
|
||||
void tests_vector_rbegin();
|
||||
void tests_vector_rend();
|
||||
void tests_vector_size();
|
||||
void tests_vector_max_size();
|
||||
void tests_vector_resize();
|
||||
void tests_vector_capacity();
|
||||
void tests_vector_empty();
|
||||
void tests_vector_reserve();
|
||||
void tests_vector_operator_access();
|
||||
void tests_vector_at();
|
||||
void tests_vector_front();
|
||||
void tests_vector_back();
|
||||
void tests_vector_assign();
|
||||
void tests_vector_push_back();
|
||||
void tests_vector_pop_back();
|
||||
void tests_vector_insert();
|
||||
void tests_vector_erase();
|
||||
void tests_vector_swap();
|
||||
void tests_vector_clear();
|
||||
void tests_vector_get_allocator();
|
||||
void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
|
||||
#endif
|
||||
49
headers/tests_proto.hpp
Normal file
49
headers/tests_proto.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef TESTS_PROTO_HPP
|
||||
# define TESTS_PROTO_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
// ************************************
|
||||
// global declarations
|
||||
struct A_test { virtual void func() = 0; };
|
||||
std::vector<A_test*> test_list;
|
||||
void add_to_list(A_test * s1, A_test * s2, A_test * s3, A_test * s4)
|
||||
{ test_list.push_back(s1)
|
||||
; test_list.push_back(s2)
|
||||
; test_list.push_back(s3)
|
||||
; test_list.push_back(s4); }
|
||||
|
||||
|
||||
// *********************************************
|
||||
// prototypes
|
||||
void test_simple();
|
||||
void tests_vector_constructor();
|
||||
void tests_vector_operator_assignation();
|
||||
void tests_vector_begin();
|
||||
void tests_vector_end();
|
||||
void tests_vector_rbegin();
|
||||
void tests_vector_rend();
|
||||
void tests_vector_size();
|
||||
void tests_vector_max_size();
|
||||
void tests_vector_resize();
|
||||
void tests_vector_capacity();
|
||||
void tests_vector_empty();
|
||||
void tests_vector_reserve();
|
||||
void tests_vector_operator_access();
|
||||
void tests_vector_at();
|
||||
void tests_vector_front();
|
||||
void tests_vector_back();
|
||||
void tests_vector_assign();
|
||||
void tests_vector_push_back();
|
||||
void tests_vector_pop_back();
|
||||
void tests_vector_insert();
|
||||
void tests_vector_erase();
|
||||
void tests_vector_swap();
|
||||
void tests_vector_clear();
|
||||
void tests_vector_get_allocator();
|
||||
void tests_vector_relational_operators();
|
||||
void tests_vector_swap_non_member();
|
||||
void tests_vector_reverse_iterators();
|
||||
|
||||
#endif
|
||||
|
||||
101
headers/tests_utils.hpp
Normal file
101
headers/tests_utils.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef TESTS_UTILS_HPP
|
||||
# define TESTS_UTILS_HPP
|
||||
|
||||
#include "colors.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iomanip> // std::setw()
|
||||
#include <iterator> // std::reverse_iterator
|
||||
#include <utility> // std::make_pair
|
||||
#include <map> // std::map
|
||||
#include <sstream>
|
||||
|
||||
|
||||
// toogle between test ft and stl
|
||||
// *************************
|
||||
#ifdef STL
|
||||
namespace ft = std;
|
||||
#else
|
||||
#include "vector.hpp"
|
||||
#include "reverse_iterator.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// global declarations
|
||||
// ************************************
|
||||
struct A_test { virtual void func() = 0; };
|
||||
extern std::vector<A_test*> test_list;
|
||||
extern void add_to_list(A_test * s1, A_test * s2, A_test * s3, A_test * s4);
|
||||
|
||||
|
||||
// struct for tests
|
||||
// ***************************************
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 0) {_val = new int[5]; _val[0] = data;}
|
||||
~mystruct() {delete[] _val;}
|
||||
int * get_data() const {return _val;}
|
||||
private:
|
||||
int * _val;
|
||||
};
|
||||
//extern std::ostream & operator<<(std::ostream & o, mystruct const & rhs);
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
o << (*rhs).get_data()[0];
|
||||
return (o);
|
||||
}
|
||||
|
||||
|
||||
// adding each test to the list
|
||||
// ***************************
|
||||
#define TEST(f_name) \
|
||||
template <class T> struct s_ ## f_name : public A_test\
|
||||
{ void func(); };\
|
||||
void f_name ()\
|
||||
{ add_to_list(\
|
||||
new(s_ ## f_name <int>)\
|
||||
,new(s_ ## f_name <char>)\
|
||||
,new(s_ ## f_name <std::string>)\
|
||||
,new(s_ ## f_name <mystruct*>)\
|
||||
);}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
|
||||
|
||||
// defines
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) ito<T>(n)
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
// generic
|
||||
template <class T>
|
||||
T ito(int n) {(void)n; return (T());
|
||||
}
|
||||
template <>
|
||||
int ito(int n) {return (n);
|
||||
}
|
||||
template <>
|
||||
char ito(int n) {return (n % 94 + 33);
|
||||
}
|
||||
template <>
|
||||
std::string ito(int n) {
|
||||
|
||||
std::string str;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << n;
|
||||
stream >> str;
|
||||
stream.clear();
|
||||
return (str);
|
||||
}
|
||||
template <>
|
||||
mystruct* ito(int n) {
|
||||
|
||||
return ( new mystruct(n) );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -2,49 +2,40 @@
|
||||
#include <string>
|
||||
#include "colors.h"
|
||||
#include <iomanip> // std::setw()
|
||||
#include "tests.hpp"
|
||||
|
||||
|
||||
// global declaration
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const & rhs) {
|
||||
o << rhs.get_data()[0];
|
||||
return (o);
|
||||
}
|
||||
std::vector<test_base *> test_list;
|
||||
test_base *test;
|
||||
std::string test_title;
|
||||
#include "tests_proto.hpp"
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
// VECTOR
|
||||
tests_vector_constructor();
|
||||
tests_vector_operator_assignation();
|
||||
tests_vector_begin();
|
||||
tests_vector_end();
|
||||
tests_vector_rbegin();
|
||||
tests_vector_rend();
|
||||
tests_vector_size();
|
||||
tests_vector_max_size();
|
||||
tests_vector_resize();
|
||||
tests_vector_capacity();
|
||||
tests_vector_empty();
|
||||
tests_vector_reserve();
|
||||
tests_vector_operator_access();
|
||||
tests_vector_at();
|
||||
tests_vector_front();
|
||||
tests_vector_back();
|
||||
tests_vector_assign();
|
||||
tests_vector_push_back();
|
||||
tests_vector_pop_back();
|
||||
tests_vector_insert();
|
||||
tests_vector_erase();
|
||||
tests_vector_swap();
|
||||
tests_vector_clear();
|
||||
tests_vector_get_allocator();
|
||||
tests_vector_relational_operators();
|
||||
tests_vector_swap_non_member();
|
||||
tests_vector_reverse_iterators();
|
||||
test_simple();
|
||||
// tests_vector_constructor();
|
||||
// tests_vector_operator_assignation();
|
||||
// tests_vector_begin();
|
||||
// tests_vector_end();
|
||||
// tests_vector_rbegin();
|
||||
// tests_vector_rend();
|
||||
// tests_vector_size();
|
||||
// tests_vector_max_size();
|
||||
// tests_vector_resize();
|
||||
// tests_vector_capacity();
|
||||
// tests_vector_empty();
|
||||
// tests_vector_reserve();
|
||||
// tests_vector_operator_access();
|
||||
// tests_vector_at();
|
||||
// tests_vector_front();
|
||||
// tests_vector_back();
|
||||
// tests_vector_assign();
|
||||
// tests_vector_push_back();
|
||||
// tests_vector_pop_back();
|
||||
// tests_vector_insert();
|
||||
// tests_vector_erase();
|
||||
// tests_vector_swap();
|
||||
// tests_vector_clear();
|
||||
// tests_vector_get_allocator();
|
||||
// tests_vector_relational_operators();
|
||||
// tests_vector_swap_non_member();
|
||||
// tests_vector_reverse_iterators();
|
||||
|
||||
// MAP
|
||||
// tests_map_constructor();
|
||||
@@ -104,7 +95,8 @@ int main() {
|
||||
{
|
||||
std::cout
|
||||
<< "\n" B_YELLOW "[" << i + 1 << "/" << size << "] "
|
||||
<< test_list[i]->title << RESET "\n";
|
||||
// << test_list[i]->title << RESET "\n";
|
||||
<< RESET "\n";
|
||||
test_list[i]->func();
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
#ifndef TESTS_VECTORS_CPP
|
||||
#define TESTS_VECTORS_CPP
|
||||
|
||||
#include "tests.hpp"
|
||||
#include "tests_utils.hpp"
|
||||
|
||||
//TEST2(test_simple(), "test")
|
||||
TEST(test_simple)
|
||||
{
|
||||
// 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) );
|
||||
|
||||
for (typename ft::vector<T>::iterator it = myvector.begin(); it != myvector.end(); ++it)
|
||||
std::cout << ' ' << *it;
|
||||
std::cout << '\n';
|
||||
}
|
||||
//TEST2END
|
||||
|
||||
/*
|
||||
void tests_vector_constructor()
|
||||
{
|
||||
TEST(vector::vector (constructor))
|
||||
@@ -1136,5 +1151,6 @@ void tests_vector_reverse_iterators()
|
||||
}
|
||||
TESTEND
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user