Add method _mismatch and _mismatch_if
This commit is contained in:
1 parent
5025b3690d
commit
6721a86768
2 files changed
+64
No files matched your search
@@ -182,6 +182,36 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _mismatch) (it_t it1, it_t it2, container_t l1, container_t l2 ) \
|
||||
{ \
|
||||
for (M_GET_IT_FIRST cont_oplist (it1, l1), \
|
||||
M_GET_IT_FIRST cont_oplist (it2, l2); \
|
||||
!M_GET_IT_END_P cont_oplist (it1) && \
|
||||
!M_GET_IT_END_P cont_oplist (it2); \
|
||||
M_GET_IT_NEXT cont_oplist (it1), \
|
||||
M_GET_IT_NEXT cont_oplist (it2)) { \
|
||||
if (!M_GET_EQUAL type_oplist (*M_GET_IT_CREF cont_oplist (it1), \
|
||||
*M_GET_IT_CREF cont_oplist (it2))) \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _mismatch_if) (it_t it1, it_t it2, container_t l1, container_t l2, bool (*func)(type_t const, type_t const) ) \
|
||||
{ \
|
||||
for (M_GET_IT_FIRST cont_oplist (it1, l1), \
|
||||
M_GET_IT_FIRST cont_oplist (it2, l2); \
|
||||
!M_GET_IT_END_P cont_oplist (it1) && \
|
||||
!M_GET_IT_END_P cont_oplist (it2); \
|
||||
M_GET_IT_NEXT cont_oplist (it1), \
|
||||
M_GET_IT_NEXT cont_oplist (it2)) { \
|
||||
if (!func (*M_GET_IT_CREF cont_oplist (it1), \
|
||||
*M_GET_IT_CREF cont_oplist (it2))) \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _map) (container_t l, void (*f)(type_t const) ) \
|
||||
{ \
|
||||
for M_EACH(item, l, cont_oplist) { \
|
||||
|
||||
@@ -86,6 +86,11 @@ static bool func_test_pos(int d)
|
||||
return d >= 0;
|
||||
}
|
||||
|
||||
static bool func_test_both_even_or_odd(int a, int b)
|
||||
{
|
||||
return (a&1) == (b&1);
|
||||
}
|
||||
|
||||
static void test_list(void)
|
||||
{
|
||||
list_int_t l;
|
||||
@@ -140,6 +145,10 @@ static void test_list(void)
|
||||
algo_list_find_if(it1, l, func_test_42);
|
||||
assert (!list_int_end_p (it1));
|
||||
assert (*list_int_cref(it1) == 42);
|
||||
|
||||
algo_list_mismatch(it1, it2, l, l);
|
||||
assert (list_int_end_p (it1));
|
||||
assert (list_int_end_p (it2));
|
||||
|
||||
for(int i = -100; i < 100; i+=2)
|
||||
list_int_push_back (l, i);
|
||||
@@ -236,6 +245,31 @@ static void test_array(void)
|
||||
assert (array_int_size(l) == 102);
|
||||
assert( algo_array_sort_p(l) == true);
|
||||
|
||||
M_LET(l2, array_int_t) {
|
||||
array_int_set(l2, l);
|
||||
array_int_it_t it1, it2;
|
||||
algo_array_mismatch(it1, it2, l, l2);
|
||||
assert (array_int_end_p (it1));
|
||||
assert (array_int_end_p (it2));
|
||||
array_int_pop_back(NULL, l2);
|
||||
array_int_push_back(l2, 159);
|
||||
algo_array_mismatch(it1, it2, l, l2);
|
||||
assert (!array_int_end_p (it1));
|
||||
assert (!array_int_end_p (it2));
|
||||
assert (*array_int_cref(it1) == 1742);
|
||||
assert (*array_int_cref(it2) == 159);
|
||||
algo_array_mismatch_if(it1, it2, l, l2, func_test_both_even_or_odd);
|
||||
assert (!array_int_end_p (it1));
|
||||
assert (!array_int_end_p (it2));
|
||||
assert (*array_int_cref(it1) == 1742);
|
||||
assert (*array_int_cref(it2) == 159);
|
||||
array_int_pop_back(NULL, l2);
|
||||
array_int_push_back(l2, 152);
|
||||
algo_array_mismatch_if(it1, it2, l, l2, func_test_both_even_or_odd);
|
||||
assert (array_int_end_p (it1));
|
||||
assert (array_int_end_p (it2));
|
||||
}
|
||||
|
||||
array_int_clean(l);
|
||||
assert (algo_array_min(l) == NULL);
|
||||
assert (algo_array_max(l) == NULL);
|
||||
|
||||
Reference in new issue
Block a user