half tests ok on map

This commit is contained in:
hugogogo
2022-06-21 14:41:24 +02:00
parent 28acc5ef51
commit 844701201f
5 changed files with 135 additions and 130 deletions

View File

@@ -47,28 +47,28 @@ void tests_vector_swap_non_member();
void tests_vector_reverse_iterators();
// map
void tests_map_simple();
//void tests_map_constructor();
//void tests_map_operator_assignation();
//void tests_map_begin();
//void tests_map_end();
//void tests_map_rbegin();
//void tests_map_rend();
//void tests_map_empty();
//void tests_map_size();
//void tests_map_max_size();
//void tests_map_operator_access();
//void tests_map_insert();
//void tests_map_erase();
//void tests_map_swap();
//void tests_map_clear();
//void tests_map_key_comp();
//void tests_map_value_comp();
//void tests_map_find();
//void tests_map_count();
//void tests_map_lower_bound();
//void tests_map_upper_bound();
//void tests_map_equal_range();
//void tests_map_get_allocator();
void tests_map_constructor();
void tests_map_operator_assignation();
void tests_map_begin();
void tests_map_end();
void tests_map_rbegin();
void tests_map_rend();
void tests_map_empty();
void tests_map_size();
void tests_map_max_size();
void tests_map_operator_access();
void tests_map_insert();
void tests_map_erase();
void tests_map_swap();
void tests_map_clear();
void tests_map_key_comp();
void tests_map_value_comp();
void tests_map_find();
void tests_map_count();
void tests_map_lower_bound();
void tests_map_upper_bound();
void tests_map_equal_range();
void tests_map_get_allocator();
#endif

View File

@@ -32,7 +32,7 @@
# define VALT(n) val<T>(n)
# define VALU(n) val<U>(n)
# define TOI(n) toi<T>(n)
# define PRINT(n) print<T>(n);
# define PRINT(n) print<>(n, #n);
# define DELETE delete_structs();
@@ -82,7 +82,10 @@ extern std::vector< mystruct* > mem_list;
template <class T, class U> struct s_ ## f_name : public A_test\
{ void func(); };\
void f_name () {\
add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
add_to_list(#f_name, "char, int", new(s_ ## f_name <char, int>));\
add_to_list(#f_name, "char, char", new(s_ ## f_name <char, char>));\
add_to_list(#f_name, "char, std::string", new(s_ ## f_name <char, std::string>));\
add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
}\
template <class T, class U>\
void s_ ## f_name <T, U>::func()
@@ -91,23 +94,25 @@ extern std::vector< mystruct* > mem_list;
// templates print
// *****************************************
template <class T>
void print(ft::vector<T> vec) {
void print(ft::vector<T> vec, std::string name) {
int i = 0;
typename ft::vector<T>::iterator it;
typename ft::vector<T>::iterator it_end = vec.end();
std::cout << "\n" << name << ":(vector)\n";
for (it = vec.begin(); it != it_end; ++it, i++)
std::cout << "[" << i << "]" << *it << " ";
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
}
template <class T, class U>
void print(ft::map<T, U> mp) {
void print(ft::map<T, U> mp, std::string name) {
int i = 0;
typename ft::map<T, U>::iterator it;
typename ft::map<T, U>::iterator it_end = mp.end();
std::cout << "\n" << name << ":(map)\n";
for (it = mp.begin(); it != it_end; ++it, i++)
std::cout << "[" << i << "]" << it->first << ":" << it->second << " ";
std::cout << "\nsize:" << mp.size() << "\n";
@@ -118,13 +123,15 @@ template <class T, class U>
// specialization in header, make it inline :
// https://stackoverflow.com/questions/63529059/c-specialized-method-templates-produce-multiple-definition-errors
template <class T>
T val(int n) {(void)n; return (T());
}
T val(int n) { (void)n; return (T()); }
template <>
inline int val(int n) {return (n);
}
inline int val(int n) { return (n); }
template <>
inline char val(int n) {return (n % 94 + 33);
inline char val(int n) {
if (n <= 126 && n >= 33)
return n;
return (n % 94 + 33);
}
template <>
inline std::string val(int n) {
@@ -144,6 +151,16 @@ template <>
mem_list.push_back(s);
return ( s );
}
template <class T>
T val(std::string str) { (void)str; return (T()); }
template <>
inline int val(std::string str) { int i = str[0]; return (val<int>(i)); }
template <>
inline char val(std::string str) { int i = str[0]; return (val<char>(i)); }
template <>
inline std::string val(std::string str) { return (str); }
template <>
inline mystruct* val(std::string str) { int i = str[0]; return (val<mystruct*>(i)); }
// templates to value