add type in tests

This commit is contained in:
hugogogo
2022-06-15 21:04:31 +02:00
parent bb4ac9963d
commit 32c413f741
5 changed files with 65 additions and 32 deletions

View File

@@ -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) );
}