diff --git a/tests/check-array.cpp b/tests/check-array.cpp index 3da5fe40..b31f2bc0 100644 --- a/tests/check-array.cpp +++ b/tests/check-array.cpp @@ -25,27 +25,18 @@ ARRAY_DEF(array_int, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL ARRAY_OPLIST(array_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::vector // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(array_int_t a, std::vector b) { size_t s = array_int_size(a); @@ -53,7 +44,7 @@ void cmp_cont(array_int_t a, std::vector b) for(size_t i = 0; i < s; i++) { int *b0 = array_int_get(a, i); int &b1 = b.at(i); - CMP_BASE(*b0, b1); + assert(*b0 == b1); } } diff --git a/tests/check-bptree-set.cpp b/tests/check-bptree-set.cpp index ed99c7d8..ca7cb942 100644 --- a/tests/check-bptree-set.cpp +++ b/tests/check-bptree-set.cpp @@ -25,27 +25,18 @@ BPTREE_DEF(tree_int, 5, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL BPTREE_OPLIST(tree_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::set // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(const tree_int_t a, const std::set &b) { tree_int_it_t ita; @@ -55,7 +46,7 @@ void cmp_cont(const tree_int_t a, const std::set &b) assert(!tree_int_end_p(ita)); const int *b0 = tree_int_cref(ita); const int &b1 = *itb; - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; tree_int_next(ita); } diff --git a/tests/check-deque.cpp b/tests/check-deque.cpp index 112ba805..786495ad 100644 --- a/tests/check-deque.cpp +++ b/tests/check-deque.cpp @@ -25,27 +25,18 @@ DEQUE_DEF(deque_float, float) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL DEQUE_OPLIST(deque_float, M_OPL_float()) // C++ Base class of the item in the container #define BASE_CLASS float -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::deque // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(deque_float_t a, std::deque b) { deque_float_it_t ita; @@ -55,7 +46,7 @@ void cmp_cont(deque_float_t a, std::deque b) assert(!deque_float_end_p(ita)); const float *b0 = deque_float_cref(ita); float &b1 = *itb; - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; deque_float_next(ita); } diff --git a/tests/check-dplist.cpp b/tests/check-dplist.cpp index fdd3b7e5..09dbf4cd 100644 --- a/tests/check-dplist.cpp +++ b/tests/check-dplist.cpp @@ -25,27 +25,18 @@ LIST_DUAL_PUSH_DEF(list_int, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL LIST_OPLIST(list_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::list // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(const list_int_t a, const std::list &b) { list_int_it_t ita; @@ -55,8 +46,7 @@ void cmp_cont(const list_int_t a, const std::list &b) assert(!list_int_end_p(ita)); const int *b0 = list_int_cref(ita); const int &b1 = *itb; - //printf("%d VS %d\n", *b0, b1); - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; list_int_next(ita); } diff --git a/tests/check-generic.hpp b/tests/check-generic.hpp index ccd8b606..8dc9ad32 100644 --- a/tests/check-generic.hpp +++ b/tests/check-generic.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Patrick Pelissier + * Copyright (c) 2021-2022 Patrick Pelissier * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,9 +37,15 @@ # define CONT_TYPE_(CONT_OPL) M_GET_TYPE CONT_OPL # define CONT_TYPE CONT_TYPE_(CONT_OPL) #endif + +// Type used for M*LIB container. Default is the same as C++ #ifndef BASE_TYPE -# define BASE_TYPE_(CONT_OPL) M_GET_SUBTYPE CONT_OPL -# define BASE_TYPE BASE_TYPE_(CONT_OPL) +# define BASE_TYPE BASE_CLASS +#endif + +// Compare the M*LIB base object to the C++ base object +#ifndef CMP_BASE +# define CMP_BASE(a, b) assert( (a) == (b) ) #endif /* Get the affectation if needed to transform an integer into C++ class (resp. M*LIB type) */ @@ -58,9 +64,27 @@ # define TYPE_IT_TO_INT(it) *(it) #endif +/* Global properties of the container */ +// Use find to perform GET_KEY for C++ +//#define HAVE_GET_KEY_THROUGH_FIND +// Container are nor ordered +//#define DONT_HAVE_SEQUENCE_IT +// associative array container +//#define HAVE_SET_KEY +// Container is in reverse +//#define HAVE_REVERSE_IT +// Have PUSH_FRONT operator +//#define HAVE_PUSH_FRONT +// Have POP_FRONT operator +//#define HAVE_POP_FRONT + +/*********************************************************************************/ + +// Define the container name, extracting it from its oplist #define CONT_NAME_(CONT_OPL) M_GET_NAME CONT_OPL #define CONT_NAME CONT_NAME_(CONT_OPL) +// Define the maximum number of tests #define MAX_TEST 28 #ifdef HAVE_REVERSE_IT @@ -456,6 +480,7 @@ void test(int select_test, int index, M_CALL_REVERSE(CONT_OPL, c0); c1.reverse(); break; + // 21 is above #endif #ifdef HAVE_PUSH_FRONT @@ -513,6 +538,7 @@ void test(int select_test, int index, // Needs SPLICE ? default: + M_STATIC_ASSERT( 28 == MAX_TEST, MLIB_INTERNAL_ERROR, "Constant MAX_TEST is no coherent with the effective number of tests"); // Nothing to do break; } diff --git a/tests/check-list.cpp b/tests/check-list.cpp index 7b835e46..502e53ad 100644 --- a/tests/check-list.cpp +++ b/tests/check-list.cpp @@ -25,27 +25,18 @@ LIST_DEF(list_int, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL LIST_OPLIST(list_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::forward_list // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(list_int_t a, std::forward_list b) { list_int_it_t ita; @@ -55,7 +46,7 @@ void cmp_cont(list_int_t a, std::forward_list b) assert(!list_int_end_p(ita)); const int *b0 = list_int_cref(ita); int &b1 = *itb; - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; list_int_next(ita); } diff --git a/tests/check-prioqueue.cpp b/tests/check-prioqueue.cpp index a7da02b2..fd94956d 100644 --- a/tests/check-prioqueue.cpp +++ b/tests/check-prioqueue.cpp @@ -27,9 +27,6 @@ #define CMP_REVERT(a,b) ((a) > (b) ? -1 : (a) < (b)) PRIOQUEUE_DEF(prio_int, int, M_OPEXTEND(M_BASIC_OPLIST, CMP(CMP_REVERT) )) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST (disable iterators & reset) #define CONT_OPL \ M_OPEXTEND( PRIOQUEUE_OPLIST(prio_int, M_OPL_int()), \ @@ -47,28 +44,20 @@ PRIOQUEUE_DEF(prio_int, int, M_OPEXTEND(M_BASIC_OPLIST, CMP(CMP_REVERT) )) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::priority_queue // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(const prio_int_t a, const std::priority_queue &b) { std::priority_queue cb = b; prio_int_t ca; prio_int_init_set(ca, a); - //printf("ca="); prio_int_out_str(stdout, ca); printf("\n"); while (!cb.empty()) { int n; prio_int_pop(&n, ca); - //printf("N=%d TOP=%d\n", n, cb.top()); assert(n == cb.top()); cb.pop(); } diff --git a/tests/check-rbtree.cpp b/tests/check-rbtree.cpp index 869ab684..cdd8e68b 100644 --- a/tests/check-rbtree.cpp +++ b/tests/check-rbtree.cpp @@ -25,27 +25,18 @@ RBTREE_DEF(tree_int, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL RBTREE_OPLIST(tree_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::set // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(const tree_int_t a, const std::set &b) { tree_int_it_t ita; @@ -55,8 +46,7 @@ void cmp_cont(const tree_int_t a, const std::set &b) assert(!tree_int_end_p(ita)); const int *b0 = tree_int_cref(ita); const int &b1 = *itb; - //printf("%d VS %d\n", *b0, b1); - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; tree_int_next(ita); } diff --git a/tests/check-umap.cpp b/tests/check-umap.cpp index 2f1696d9..9852a117 100644 --- a/tests/check-umap.cpp +++ b/tests/check-umap.cpp @@ -30,7 +30,6 @@ DICT_DEF2(dict_int, int, int) // C++ Base class of the item in the container #define BASE_CLASS int -#define BASE_TYPE int // C++ Container class #define CONT_CLASS std::unordered_map @@ -38,9 +37,7 @@ DICT_DEF2(dict_int, int, int) // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - +// Get the value from the iterator #define CLASS_IT_TO_INT(it) (it)->second #define TYPE_IT_TO_INT(it) (it)->value @@ -51,7 +48,7 @@ void cmp_cont(const dict_int_t a, const std::unordered_map &b) while (itb != b.end()) { const int *b0 = dict_int_get(a, itb->first); assert(b0 != nullptr); - CMP_BASE(*b0, itb->second); + assert(*b0 == itb->second); itb++; n++; } @@ -60,8 +57,11 @@ void cmp_cont(const dict_int_t a, const std::unordered_map &b) #define DEFAULT_NUMBER 1000000 +// Use find to perform GET_KEY for C++ #define HAVE_GET_KEY_THROUGH_FIND +// Container are nor ordered #define DONT_HAVE_SEQUENCE_IT +// associative array container #define HAVE_SET_KEY #define push_back insert diff --git a/tests/check-uset.cpp b/tests/check-uset.cpp index 8226b191..b6aaf566 100644 --- a/tests/check-uset.cpp +++ b/tests/check-uset.cpp @@ -25,27 +25,18 @@ DICT_SET_DEF(dict_int, int) -// Transform an integer 'i' into a M*LIB base item 'a' -#define TYPE_SET_INT(a, i) (a) = (i) - // Container OPLIST #define CONT_OPL DICT_SET_OPLIST(dict_int, M_OPL_int()) // C++ Base class of the item in the container #define BASE_CLASS int -// Transform an integer 'i' into a C++ base item 'a' -#define CLASS_SET_INT(a, i) (a) = (i) - // C++ Container class #define CONT_CLASS std::unordered_set // Compare the M*LIB container a to the C++ container b #define CMP_CONT(a, b) cmp_cont(a, b) -// Compare the M*LIB base object to the C++ base object -#define CMP_BASE(a, b) assert( (a) == (b) ) - void cmp_cont(const dict_int_t a, const std::unordered_set &b) { size_t n = 0; @@ -54,7 +45,7 @@ void cmp_cont(const dict_int_t a, const std::unordered_set &b) const int &b1 = *itb; const int *b0 = dict_int_get(a, b1); assert(b0 != nullptr); - CMP_BASE(*b0, b1); + assert(*b0 == b1); itb++; n++; }