116 lines
2.6 KiB
C++
116 lines
2.6 KiB
C++
#ifndef TESTS_UTILS_HPP
|
|
# define TESTS_UTILS_HPP
|
|
|
|
#include "colors.h"
|
|
#include "A_test.hpp"
|
|
#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
|
|
// ************************************
|
|
extern std::vector<A_test*> test_list;
|
|
extern void add_to_list(std::string s, 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(\
|
|
#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()
|
|
|
|
|
|
// defines
|
|
// ****************************************
|
|
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
|
# define VAL(n) val<T>(n)
|
|
# define PRINT(n) print_vector<T>(n)
|
|
|
|
|
|
// get a value
|
|
// *********************************************
|
|
template <class T>
|
|
T val(int n) {(void)n; return (T());
|
|
}
|
|
template <>
|
|
int val(int n) {return (n);
|
|
}
|
|
template <>
|
|
char val(int n) {return (n % 94 + 33);
|
|
}
|
|
template <>
|
|
std::string val(int n) {
|
|
|
|
std::string str;
|
|
std::stringstream stream;
|
|
|
|
stream << n;
|
|
stream >> str;
|
|
stream.clear();
|
|
return (str);
|
|
}
|
|
template <>
|
|
mystruct* val(int n) {
|
|
|
|
return ( new mystruct(n) );
|
|
}
|
|
|
|
|
|
// get a value
|
|
// *********************************************
|
|
template <class T>
|
|
void print_vector(ft::vector<T> vec)
|
|
{
|
|
int i = 0;
|
|
for (typename ft::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it, i++)
|
|
std::cout << "[" << i << "]" << *it << " ";
|
|
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
|
}
|
|
|
|
|
|
#endif
|
|
|