From 9cb03ab74cd6f1156345b1826f0a20640fc9d501 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Mon, 17 Jul 2023 13:11:40 +0200 Subject: [PATCH] use charpint.hh --- tests/func/test_integral.cc | 37 +++++----- tests/func/test_swisstable.cc | 134 +++++++++++++++++----------------- 2 files changed, 86 insertions(+), 85 deletions(-) diff --git a/tests/func/test_integral.cc b/tests/func/test_integral.cc index 19c0f656..f0361d1d 100644 --- a/tests/func/test_integral.cc +++ b/tests/func/test_integral.cc @@ -31,10 +31,11 @@ typedef unsigned char unsigned_char; #include #include "charpint.hh" + typedef char *charp; #define TK charp +#define T int #define POD -#define T float #include #define POD @@ -107,18 +108,18 @@ void print_deq_int(deq_int *a) int main(void) { -#define TEST_LIST(type, v1, v2) \ - { \ - type a = type##_init(); \ - type##_push_back(&a, v1); \ - type##_it found = type##_find(&a, v1); \ - assert(!type##_it_done(&found)); /* equal */ \ - type##_push_back(&a, v2); \ - type b = type##_copy(&a); \ - type##_sort(&a); /* compare */ \ - assert(type##_equal(&a, &b)); \ - type##_free(&a); \ - type##_free(&b); \ +#define TEST_LIST(type, v1, v2) \ + { \ + type a = type##_init(); \ + type##_push_back(&a, v1); \ + type##_it found = type##_find(&a, v1); \ + assert(!type##_it_done(&found)); /* equal */ \ + type##_push_back(&a, v2); \ + type b = type##_copy(&a); \ + type##_sort(&a); /* compare */ \ + assert(type##_equal(&a, &b)); \ + type##_free(&a); \ + type##_free(&b); \ } TEST_LIST(deq_int, 1, 2); @@ -136,11 +137,11 @@ int main(void) stack_uint8_t_free(&a); } { - map_charpfloat a = map_charpfloat_init(NULL); - map_charpfloat_insert(&a, 1.f); // compare - map_charpfloat_it found = map_charpfloat_find(&a, 1.f); - assert(!map_charpfloat_it_done(&found)); // equal - map_charpfloat_free(&a); + map_charpint a = map_charpint_init(NULL); + map_charpint_insert(&a, 1.f); // compare + map_charpint_it found = map_charpint_find(&a, 1.f); + assert(!map_charpint_it_done(&found)); // equal + map_charpint_free(&a); } TEST_LIST(vec_double, 1.0, 2.0); { diff --git a/tests/func/test_swisstable.cc b/tests/func/test_swisstable.cc index 8360143b..0c6a7af0 100644 --- a/tests/func/test_swisstable.cc +++ b/tests/func/test_swisstable.cc @@ -21,44 +21,44 @@ typedef char* charp; #include #include -#define FOREACH_METH(TEST) \ - TEST(SELF) \ - TEST(INSERT) \ - TEST(INSERT_FOUND) \ - TEST(CONTAINS) \ - TEST(CLEAR) \ - TEST(SWAP) \ - TEST(COUNT) \ - TEST(FIND) \ - TEST(COPY) \ - TEST(EQUAL) \ - TEST(REHASH) \ - TEST(RESERVE) \ - TEST(FIND_IF) \ +#define FOREACH_METH(TEST) \ + TEST(SELF) \ + TEST(INSERT) \ + TEST(INSERT_FOUND) \ + TEST(CONTAINS) \ + TEST(CLEAR) \ + TEST(SWAP) \ + TEST(COUNT) \ + TEST(FIND) \ + TEST(COPY) \ + TEST(EQUAL) \ + TEST(REHASH) \ + TEST(RESERVE) \ + TEST(FIND_IF) \ TEST(FIND_IF_NOT) -#define FOREACH_DEBUG(TEST) \ - TEST(ERASE) \ - TEST(ERASE_IF) \ - TEST(ALL_OF) \ - TEST(ANY_OF) \ - TEST(NONE_OF) \ - TEST(COUNT_IF) \ - TEST(UNION) /* 20 */ \ - TEST(INTERSECTION) \ - TEST(DIFFERENCE) \ - TEST(SYMMETRIC_DIFFERENCE) \ - TEST(GENERATE) \ - TEST(GENERATE_N) \ - TEST(TRANSFORM) \ - TEST(COPY_IF) \ - TEST(EMPLACE) \ - TEST(EMPLACE_FOUND) \ - TEST(EMPLACE_HINT) /* 30 */ \ - TEST(MERGE) \ - TEST(MERGE_RANGE) \ - TEST(EXTRACT) /* 33 */ \ - TEST(INSERT_GENERIC) \ +#define FOREACH_DEBUG(TEST) \ + TEST(ERASE) \ + TEST(ERASE_IF) \ + TEST(ALL_OF) \ + TEST(ANY_OF) \ + TEST(NONE_OF) \ + TEST(COUNT_IF) \ + TEST(UNION) /* 20 */ \ + TEST(INTERSECTION) \ + TEST(DIFFERENCE) \ + TEST(SYMMETRIC_DIFFERENCE) \ + TEST(GENERATE) \ + TEST(GENERATE_N) \ + TEST(TRANSFORM) \ + TEST(COPY_IF) \ + TEST(EMPLACE) \ + TEST(EMPLACE_FOUND) \ + TEST(EMPLACE_HINT) /* 30 */ \ + TEST(MERGE) \ + TEST(MERGE_RANGE) \ + TEST(EXTRACT) /* 33 */ \ + TEST(INSERT_GENERIC) \ TEST(REMOVE_IF) #define GENERATE_ENUM(x) TEST_##x, @@ -82,39 +82,39 @@ static const char *test_names[] = { ""}; #endif -#define CHECK(_x, _y) \ - { \ - assert(_x.size == _y.size()); \ - if (_x.size > 0) \ - { \ - size_t a_found = 0; \ - size_t b_found = 0; \ - foreach (hmap_charp, &_x, _it) \ - { \ - str *_key = &_it.ref->key; \ - auto _found = _y.find(str_c_str(_key)); \ - assert(_found != _y.end()); \ - a_found++; \ - } \ - for (auto x : _y) \ - { \ - const char *_key = x.first.c_str(); \ - hmap_charp_it _found = hmap_charp_find(&_x, key); \ - assert(!hmap_charp_it_done(&_found)); \ - strint_free(&d); \ - b_found++; \ - } \ - assert(a_found == b_found); \ - } \ +#define CHECK(_x, _y) \ + { \ + assert(_x.size == _y.size()); \ + if (_x.size > 0) \ + { \ + size_t a_found = 0; \ + size_t b_found = 0; \ + foreach (hmap_charp, &_x, _it) \ + { \ + str *_key = &_it.ref->key; \ + auto _found = _y.find(str_c_str(_key)); \ + assert(_found != _y.end()); \ + a_found++; \ + } \ + for (auto x : _y) \ + { \ + const char *_key = x.first.c_str(); \ + hmap_charp_it _found = hmap_charp_find(&_x, key); \ + assert(!hmap_charp_it_done(&_found)); \ + strint_free(&d); \ + b_found++; \ + } \ + assert(a_found == b_found); \ + } \ } -#define CHECK_ITER(_it, b, _iter) \ - if (!hmap_charp_it_done(&_it)) \ - { \ - assert(_iter != b.end()); \ - assert(*_it.ref->value == *(*_iter).value); \ - } \ - else \ +#define CHECK_ITER(_it, b, _iter) \ + if (!hmap_charp_it_done(&_it)) \ + { \ + assert(_iter != b.end()); \ + assert(*_it.ref->value == *(*_iter).value); \ + } \ + else \ assert(_iter == b.end()) #ifdef DEBUG