Skip to content

Commit

Permalink
use charpint.hh
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Feb 21, 2024
1 parent be5aea2 commit 9cb03ab
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 85 deletions.
37 changes: 19 additions & 18 deletions tests/func/test_integral.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ typedef unsigned char unsigned_char;
#include <ctl/stack.h>

#include "charpint.hh"

typedef char *charp;
#define TK charp
#define T int
#define POD
#define T float
#include <ctl/map.h>

#define POD
Expand Down Expand Up @@ -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);
Expand All @@ -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);
{
Expand Down
134 changes: 67 additions & 67 deletions tests/func/test_swisstable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,44 @@ typedef char* charp;
#include <unordered_set>
#include <unordered_map>

#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,
Expand All @@ -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
Expand Down

0 comments on commit 9cb03ab

Please sign in to comment.