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