re-organisation of files
This commit is contained in:
117
tests/tests_utils.cpp
Normal file
117
tests/tests_utils.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
#include "tests.hpp"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void delete_structs() {
|
||||
|
||||
std::vector<mystruct*>::iterator it;
|
||||
std::vector<mystruct*>::iterator it_end = mem_list.end();
|
||||
|
||||
for (it = mem_list.begin(); it != it_end; ++it)
|
||||
delete *it;
|
||||
mem_list.clear();
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
// mystruct
|
||||
// *********************************************
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
// 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] );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user