add type in tests
This commit is contained in:
1
Makefile
1
Makefile
@@ -57,6 +57,7 @@ D_HEADERS = ./headers
|
|||||||
HEADERS = colors.h \
|
HEADERS = colors.h \
|
||||||
tests_utils.hpp \
|
tests_utils.hpp \
|
||||||
tests_proto.hpp \
|
tests_proto.hpp \
|
||||||
|
A_test.hpp \
|
||||||
\
|
\
|
||||||
enable_if.hpp \
|
enable_if.hpp \
|
||||||
iterator_traits.hpp \
|
iterator_traits.hpp \
|
||||||
|
|||||||
14
headers/A_test.hpp
Normal file
14
headers/A_test.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef A_TEST_HPP
|
||||||
|
# define A_TEST_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct A_test
|
||||||
|
{
|
||||||
|
std::string title;
|
||||||
|
std::string type;
|
||||||
|
virtual void func() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -2,16 +2,29 @@
|
|||||||
# define TESTS_PROTO_HPP
|
# define TESTS_PROTO_HPP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "A_test.hpp"
|
||||||
|
|
||||||
// ************************************
|
// ************************************
|
||||||
// global declarations
|
// global declarations
|
||||||
struct A_test { virtual void func() = 0; };
|
std::vector< std::vector<A_test*> > test_list;
|
||||||
std::vector<A_test*> test_list;
|
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4) {
|
||||||
void add_to_list(A_test * s1, A_test * s2, A_test * s3, A_test * s4)
|
|
||||||
{ test_list.push_back(s1)
|
std::vector<A_test*> test_sub_list;
|
||||||
; test_list.push_back(s2)
|
|
||||||
; test_list.push_back(s3)
|
s1->title = s;
|
||||||
; test_list.push_back(s4); }
|
s2->title = s;
|
||||||
|
s3->title = s;
|
||||||
|
s4->title = s;
|
||||||
|
s1->type = "int";
|
||||||
|
s2->type = "char";
|
||||||
|
s3->type = "std::string";
|
||||||
|
s4->type = "mystruct";
|
||||||
|
test_sub_list.push_back(s1);
|
||||||
|
test_sub_list.push_back(s2);
|
||||||
|
test_sub_list.push_back(s3);
|
||||||
|
test_sub_list.push_back(s4);
|
||||||
|
test_list.push_back(test_sub_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// *********************************************
|
// *********************************************
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# define TESTS_UTILS_HPP
|
# define TESTS_UTILS_HPP
|
||||||
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
#include "A_test.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -24,9 +25,8 @@
|
|||||||
|
|
||||||
// global declarations
|
// global declarations
|
||||||
// ************************************
|
// ************************************
|
||||||
struct A_test { virtual void func() = 0; };
|
|
||||||
extern std::vector<A_test*> test_list;
|
extern std::vector<A_test*> test_list;
|
||||||
extern void add_to_list(A_test * s1, A_test * s2, A_test * s3, A_test * s4);
|
extern void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||||
|
|
||||||
|
|
||||||
// struct for tests
|
// struct for tests
|
||||||
@@ -49,39 +49,39 @@ std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
|||||||
// adding each test to the list
|
// adding each test to the list
|
||||||
// ***************************
|
// ***************************
|
||||||
#define TEST(f_name) \
|
#define TEST(f_name) \
|
||||||
template <class T> struct s_ ## f_name : public A_test\
|
template <class T> struct s_ ## f_name : public A_test\
|
||||||
{ void func(); };\
|
{ void func(); };\
|
||||||
void f_name ()\
|
void f_name ()\
|
||||||
{ add_to_list(\
|
{ add_to_list(\
|
||||||
new(s_ ## f_name <int>)\
|
#f_name,\
|
||||||
,new(s_ ## f_name <char>)\
|
new(s_ ## f_name <int>),\
|
||||||
,new(s_ ## f_name <std::string>)\
|
new(s_ ## f_name <char>),\
|
||||||
,new(s_ ## f_name <mystruct*>)\
|
new(s_ ## f_name <std::string>),\
|
||||||
|
new(s_ ## f_name <mystruct*>)\
|
||||||
);}\
|
);}\
|
||||||
template <class T>\
|
template <class T>\
|
||||||
void s_ ## f_name <T>::func()
|
void s_ ## f_name <T>::func()
|
||||||
|
|
||||||
|
|
||||||
// defines
|
// defines
|
||||||
// ****************************************
|
// ****************************************
|
||||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||||
# define VAL(n) ito<T>(n)
|
# define VAL(n) val<T>(n)
|
||||||
|
|
||||||
|
|
||||||
// get a value
|
// get a value
|
||||||
// *********************************************
|
// *********************************************
|
||||||
// generic
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T ito(int n) {(void)n; return (T());
|
T val(int n) {(void)n; return (T());
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
int ito(int n) {return (n);
|
int val(int n) {return (n);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
char ito(int n) {return (n % 94 + 33);
|
char val(int n) {return (n % 94 + 33);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
std::string ito(int n) {
|
std::string val(int n) {
|
||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
@@ -92,7 +92,7 @@ template <>
|
|||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
mystruct* ito(int n) {
|
mystruct* val(int n) {
|
||||||
|
|
||||||
return ( new mystruct(n) );
|
return ( new mystruct(n) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,13 +91,18 @@ int main() {
|
|||||||
|
|
||||||
// execute tests and print them :
|
// execute tests and print them :
|
||||||
int size = test_list.size();
|
int size = test_list.size();
|
||||||
|
int sub_size;
|
||||||
for(int i = 0; i < size; i++)
|
for(int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
std::cout
|
std::cout << "\n" B_YELLOW "[" << i + 1 << "/" << size << "] "
|
||||||
<< "\n" B_YELLOW "[" << i + 1 << "/" << size << "] "
|
<< test_list[i][0]->title << RESET << "\n";
|
||||||
// << test_list[i]->title << RESET "\n";
|
sub_size = test_list[i].size();
|
||||||
<< RESET "\n";
|
for (int j = 0; j < sub_size; j++)
|
||||||
test_list[i]->func();
|
{
|
||||||
|
std::cout << "\n" << B_CYAN << "-- " << test_list[i][j]->type
|
||||||
|
<< " --" << RESET "\n";
|
||||||
|
test_list[i][j]->func();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user