tests for map ope

This commit is contained in:
hugogogo
2022-06-19 12:33:18 +02:00
parent 50224fb432
commit 3074f7c93c
3 changed files with 49 additions and 35 deletions

View File

@@ -28,6 +28,8 @@
// **************************************** // ****************************************
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n"; # define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
# define VAL(n) val<T>(n) # define VAL(n) val<T>(n)
# define VALT(n) val<T>(n)
# define VALU(n) val<U>(n)
# define TOI(n) toi<T>(n) # define TOI(n) toi<T>(n)
# define PRINT(n) print<T>(n); # define PRINT(n) print<T>(n);
# define DELETE delete_structs(); # define DELETE delete_structs();
@@ -63,7 +65,7 @@ extern std::vector< mystruct* > mem_list;
// adding each test to the list // adding each test to the list
// *************************** // ***************************
#define TEST(f_name) \ #define TEST_V(f_name) \
template <class T> struct s_ ## f_name : public A_test\ template <class T> struct s_ ## f_name : public A_test\
{ void func(); };\ { void func(); };\
void f_name () {\ void f_name () {\
@@ -75,6 +77,18 @@ extern std::vector< mystruct* > mem_list;
template <class T>\ template <class T>\
void s_ ## f_name <T>::func() void s_ ## f_name <T>::func()
#define TEST_M(f_name) \
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("", "char, int", new(s_ ## f_name <char, int>));\
add_to_list("", "std::string, int", new(s_ ## f_name <std::string, int>));\
add_to_list("", "mystruct*, int", new(s_ ## f_name <mystruct*, int>));\
}\
template <class T, class U>\
void s_ ## f_name <T, U>::func()
// templates print // templates print
// ***************************************** // *****************************************

View File

@@ -4,18 +4,18 @@
#include "tests_utils.hpp" #include "tests_utils.hpp"
TEST(tests_map_simple) TEST_M(tests_map_simple)
{ {
// title // title
TITLE(simple test) TITLE(simple test)
typename std::map<T, int> first; typename std::map<T, U> first;
typename std::map<T, int>::iterator it; typename std::map<T, U>::iterator it;
first[VAL('a')]=10; first[VALT('a')]=VALU(10);
first[VAL('b')]=30; first[VALT('b')]=VALU(30);
first[VAL('c')]=50; first[VALT('c')]=VALU(50);
first[VAL('d')]=70; first[VALT('d')]=VALU(70);
for(it=first.begin(); it!=first.end(); ++it){ for(it=first.begin(); it!=first.end(); ++it){
std::cout << it->first << " => " << it->second << '\n'; std::cout << it->first << " => " << it->second << '\n';

View File

@@ -4,7 +4,7 @@
#include "tests_utils.hpp" #include "tests_utils.hpp"
TEST(tests_vector_constructor) TEST_V(tests_vector_constructor)
{ {
// title // title
TITLE(cplusplus.com reference) TITLE(cplusplus.com reference)
@@ -24,7 +24,7 @@ TEST(tests_vector_constructor)
DELETE DELETE
} }
TEST(tests_vector_operator_assignation) TEST_V(tests_vector_operator_assignation)
{ {
// title // title
TITLE(cplusplus.com reference) TITLE(cplusplus.com reference)
@@ -51,7 +51,7 @@ TEST(tests_vector_operator_assignation)
DELETE DELETE
} }
TEST(tests_vector_begin) TEST_V(tests_vector_begin)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -65,7 +65,7 @@ TEST(tests_vector_begin)
DELETE DELETE
} }
TEST(tests_vector_end) TEST_V(tests_vector_end)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -79,7 +79,7 @@ TEST(tests_vector_end)
DELETE DELETE
} }
TEST(tests_vector_rbegin) TEST_V(tests_vector_rbegin)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -98,7 +98,7 @@ TEST(tests_vector_rbegin)
DELETE DELETE
} }
TEST(tests_vector_rend) TEST_V(tests_vector_rend)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -117,7 +117,7 @@ TEST(tests_vector_rend)
DELETE DELETE
} }
TEST(tests_vector_size) TEST_V(tests_vector_size)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -139,7 +139,7 @@ TEST(tests_vector_size)
DELETE DELETE
} }
TEST(tests_vector_max_size) TEST_V(tests_vector_max_size)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -158,7 +158,7 @@ TEST(tests_vector_max_size)
DELETE DELETE
} }
TEST(tests_vector_resize) TEST_V(tests_vector_resize)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -242,7 +242,7 @@ TEST(tests_vector_resize)
DELETE DELETE
} }
TEST(tests_vector_capacity) TEST_V(tests_vector_capacity)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -259,7 +259,7 @@ TEST(tests_vector_capacity)
DELETE DELETE
} }
TEST(tests_vector_empty) TEST_V(tests_vector_empty)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -280,7 +280,7 @@ TEST(tests_vector_empty)
DELETE DELETE
} }
TEST(tests_vector_reserve) TEST_V(tests_vector_reserve)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -314,7 +314,7 @@ TEST(tests_vector_reserve)
DELETE DELETE
} }
TEST(tests_vector_operator_access) TEST_V(tests_vector_operator_access)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -340,7 +340,7 @@ TEST(tests_vector_operator_access)
DELETE DELETE
} }
TEST(tests_vector_at) TEST_V(tests_vector_at)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -357,7 +357,7 @@ TEST(tests_vector_at)
DELETE DELETE
} }
TEST(tests_vector_front) TEST_V(tests_vector_front)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -378,7 +378,7 @@ TEST(tests_vector_front)
DELETE DELETE
} }
TEST(tests_vector_back) TEST_V(tests_vector_back)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -397,7 +397,7 @@ TEST(tests_vector_back)
DELETE DELETE
} }
TEST(tests_vector_assign) TEST_V(tests_vector_assign)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -466,7 +466,7 @@ TEST(tests_vector_assign)
DELETE DELETE
} }
TEST(tests_vector_push_back) TEST_V(tests_vector_push_back)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -498,7 +498,7 @@ TEST(tests_vector_push_back)
DELETE DELETE
} }
TEST(tests_vector_pop_back) TEST_V(tests_vector_pop_back)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -529,7 +529,7 @@ TEST(tests_vector_pop_back)
DELETE DELETE
} }
TEST(tests_vector_insert) TEST_V(tests_vector_insert)
{ {
typename ft::vector<T>::iterator it; typename ft::vector<T>::iterator it;
@@ -615,7 +615,7 @@ TEST(tests_vector_insert)
DELETE DELETE
} }
TEST(tests_vector_erase) TEST_V(tests_vector_erase)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -656,7 +656,7 @@ TEST(tests_vector_erase)
DELETE DELETE
} }
TEST(tests_vector_swap) TEST_V(tests_vector_swap)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -675,7 +675,7 @@ TEST(tests_vector_swap)
DELETE DELETE
} }
TEST(tests_vector_clear) TEST_V(tests_vector_clear)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -698,7 +698,7 @@ TEST(tests_vector_clear)
DELETE DELETE
} }
TEST(tests_vector_get_allocator) TEST_V(tests_vector_get_allocator)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -724,7 +724,7 @@ TEST(tests_vector_get_allocator)
DELETE DELETE
} }
TEST(tests_vector_relational_operators) TEST_V(tests_vector_relational_operators)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -742,7 +742,7 @@ TEST(tests_vector_relational_operators)
DELETE DELETE
} }
TEST(tests_vector_swap_non_member) TEST_V(tests_vector_swap_non_member)
{ {
// title // title
TITLE(cplusplus.com reference :) TITLE(cplusplus.com reference :)
@@ -761,7 +761,7 @@ TEST(tests_vector_swap_non_member)
DELETE DELETE
} }
TEST(tests_vector_reverse_iterators) TEST_V(tests_vector_reverse_iterators)
{ {
// title // title
TITLE(cplusplus.com reference) TITLE(cplusplus.com reference)