tests are receving as much argument as necessary, and print works with map
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
#ifndef TESTS_A_HPP
|
||||
# define TESTS_A_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
struct A_test
|
||||
{
|
||||
virtual ~A_test(){};
|
||||
std::string title;
|
||||
std::string type;
|
||||
virtual void func() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef TESTS_MYSTRUCT_HPP
|
||||
# define TESTS_MYSTRUCT_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
struct mystruct {
|
||||
|
||||
public:
|
||||
mystruct(int data = 0);
|
||||
~mystruct();
|
||||
int * get_data() const;
|
||||
|
||||
private:
|
||||
int * _val;
|
||||
|
||||
};
|
||||
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
|
||||
#include "tests_utils.hpp"
|
||||
|
||||
// print vector
|
||||
// ********************************************
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::vector<T>::iterator it;
|
||||
typename ft::vector<T>::iterator it_end = vec.end();
|
||||
|
||||
for (it = vec.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\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) {
|
||||
|
||||
mystruct *s = new mystruct(n);
|
||||
mem_list.push_back(s);
|
||||
return ( s );
|
||||
}
|
||||
|
||||
|
||||
// convert a value
|
||||
// *****************************************
|
||||
template <class T>
|
||||
int toi(T t) {(void)t; return (0);
|
||||
}
|
||||
template <>
|
||||
int toi(int i) {return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(char c) {return (c);
|
||||
}
|
||||
template <>
|
||||
int toi(std::string str) {
|
||||
|
||||
int i;
|
||||
std::stringstream stream;
|
||||
|
||||
stream << str;
|
||||
stream >> i;
|
||||
stream.clear();
|
||||
return (i);
|
||||
}
|
||||
template <>
|
||||
int toi(mystruct* s) {
|
||||
|
||||
return ( s->get_data()[0] );
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define TOI(n) toi<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n);
|
||||
# define PRINT(n) print<T>(n);
|
||||
# define DELETE delete_structs();
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
int * _val;
|
||||
};
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs);
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
void add_to_list(std::string title, std::string type, A_test* test);
|
||||
void delete_structs();
|
||||
|
||||
|
||||
@@ -66,14 +66,12 @@ extern std::vector< mystruct* > mem_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*>)\
|
||||
);}\
|
||||
void f_name () {\
|
||||
add_to_list(#f_name, "int", new(s_ ## f_name <int>));\
|
||||
add_to_list("", "char", new(s_ ## f_name <char>));\
|
||||
add_to_list("", "std::string", new(s_ ## f_name <std::string>));\
|
||||
add_to_list("", "mystruct*", new(s_ ## f_name <mystruct*>));\
|
||||
}\
|
||||
template <class T>\
|
||||
void s_ ## f_name <T>::func()
|
||||
|
||||
@@ -81,7 +79,7 @@ extern std::vector< mystruct* > mem_list;
|
||||
// templates print
|
||||
// *****************************************
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec) {
|
||||
void print(ft::vector<T> vec) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::vector<T>::iterator it;
|
||||
@@ -91,6 +89,17 @@ template <class T>
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
template <class T, class U>
|
||||
void print(ft::map<T, U> ma) {
|
||||
|
||||
int i = 0;
|
||||
typename ft::map<T, U>::iterator it;
|
||||
typename ft::map<T, U>::iterator it_end = ma.end();
|
||||
|
||||
for (it = ma.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << it->first << ":" << it->second << " ";
|
||||
std::cout << "\nsize:" << ma.size() << "\n";
|
||||
}
|
||||
|
||||
// templates get value
|
||||
// *************************************
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
int main() {
|
||||
|
||||
// VECTOR
|
||||
// tests_vector_constructor();
|
||||
tests_vector_constructor();
|
||||
// tests_vector_operator_assignation();
|
||||
// tests_vector_begin();
|
||||
// tests_vector_end();
|
||||
@@ -34,7 +34,7 @@ int main() {
|
||||
// tests_vector_reverse_iterators();
|
||||
|
||||
// MAP
|
||||
// tests_map_simple();
|
||||
tests_map_simple();
|
||||
// tests_map_constructor();
|
||||
// tests_map_operator_assignation();
|
||||
// tests_map_begin();
|
||||
|
||||
@@ -4,23 +4,19 @@
|
||||
|
||||
// functions
|
||||
// **********************************************
|
||||
void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4) {
|
||||
void add_to_list(std::string title, std::string type, A_test* test) {
|
||||
|
||||
std::vector<A_test*> test_sub_list;
|
||||
std::vector<A_test*> test_sub_list;
|
||||
std::vector< std::vector<A_test*> >::iterator it;
|
||||
|
||||
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);
|
||||
// title != NULL for the first element
|
||||
if (!title.empty())
|
||||
test_list.push_back(test_sub_list);
|
||||
|
||||
test->title = title;
|
||||
test->type = type;
|
||||
it = test_list.end() - 1;
|
||||
(*it).push_back(test);
|
||||
}
|
||||
void delete_structs() {
|
||||
|
||||
|
||||
@@ -9,17 +9,18 @@ TEST(tests_map_simple)
|
||||
// title
|
||||
TITLE(simple test)
|
||||
|
||||
std::map<char,int> first;
|
||||
std::map<char, int>::iterator it;
|
||||
typename std::map<T, int> first;
|
||||
typename std::map<T, int>::iterator it;
|
||||
|
||||
first['a']=10;
|
||||
first['b']=30;
|
||||
first['c']=50;
|
||||
first['d']=70;
|
||||
first[VAL('a')]=10;
|
||||
first[VAL('b')]=30;
|
||||
first[VAL('c')]=50;
|
||||
first[VAL('d')]=70;
|
||||
|
||||
for(it=first.begin(); it!=first.end(); ++it){
|
||||
std::cout << it->first << " => " << it->second << '\n';
|
||||
}
|
||||
PRINT(first)
|
||||
|
||||
DELETE
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
#include "tests_mystruct.hpp"
|
||||
|
||||
mystruct::mystruct(int data)
|
||||
{_val = new int[2]; _val[0] = data; _val[1] = data;}
|
||||
|
||||
mystruct::~mystruct()
|
||||
{delete[] _val;}
|
||||
|
||||
int * mystruct::get_data() const
|
||||
{return _val;}
|
||||
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
if (rhs != NULL)
|
||||
o << (*rhs).get_data()[0] << "," << (*rhs).get_data()[1];
|
||||
else
|
||||
o << "NULL";
|
||||
return (o);
|
||||
}
|
||||
Reference in New Issue
Block a user