Commit 63ac6d1d authored by Chris Müller's avatar Chris Müller

test: add testcases for map primitives.

parent 2e62a3f0
#include "unittest.h"
#include "structures/map.h"
#include "utf8.h"
#include <assert.h>
static cry_ordering_funptr cmp = cry_cast(cry_ordering_funptr, cry_utf8_compare);
static void
test_map_init(const_pointer nothing)
{
struct CryMap* map = cry_map_new(cmp);
assert(map != 0);
assert(cry_map_size(map) == 0);
cry_map_clear(map, 0, 0);
cry_free(map);
}
static void
test_map_lookup(const_pointer nothing)
{
struct CryMap* map = cry_map_new(cmp);
int i[] = { 1, 2, 3, 4, 5, 6 };
cry_map_insert(map, "1", i);
cry_map_insert(map, "2", i + 1);
cry_map_insert(map, "3", i + 2);
cry_map_insert(map, "4", i + 3);
cry_map_insert(map, "5", i + 4);
cry_map_insert(map, "6", i + 5);
assert(cry_map_size(map) == 6);
assert(cry_map_lookup(map, "1") == i);
assert(cry_map_lookup(map, "2") == i + 1);
assert(cry_map_lookup(map, "3") == i + 2);
assert(cry_map_lookup(map, "4") == i + 3);
assert(cry_map_lookup(map, "5") == i + 4);
assert(cry_map_lookup(map, "6") == i + 5);
cry_map_clear(map, 0, 0);
assert(cry_map_size(map) == 0);
assert(cry_map_lookup(map, "1") == 0);
assert(cry_map_lookup(map, "2") == 0);
assert(cry_map_lookup(map, "3") == 0);
assert(cry_map_lookup(map, "4") == 0);
assert(cry_map_lookup(map, "5") == 0);
assert(cry_map_lookup(map, "6") == 0);
cry_free(map);
}
static void
test_map_removal(const_pointer nothing)
{
struct CryMap* map = cry_map_new(cmp);
int i[] = { 1, 2, 3, 4, 5, 6 };
assert(map != 0);
cry_map_insert(map, "1", i);
cry_map_insert(map, "2", i + 1);
cry_map_insert(map, "3", i + 2);
cry_map_insert(map, "4", i + 3);
cry_map_insert(map, "5", i + 4);
cry_map_insert(map, "6", i + 5);
assert(cry_map_size(map) == 6);
assert(cry_map_lookup(map, "1") == i);
assert(cry_map_lookup(map, "2") == i + 1);
assert(cry_map_lookup(map, "3") == i + 2);
assert(cry_map_lookup(map, "4") == i + 3);
assert(cry_map_lookup(map, "5") == i + 4);
assert(cry_map_lookup(map, "6") == i + 5);
assert(cry_map_remove(map, "3").data == i + 2);
assert(cry_map_remove(map, "5").data == i + 4);
assert(cry_map_remove(map, "6").data == i + 5);
assert(cry_map_lookup(map, "3") == 0);
assert(cry_map_lookup(map, "5") == 0);
assert(cry_map_lookup(map, "6") == 0);
cry_map_clear(map, 0, 0);
assert(cry_map_size(map) == 0);
cry_free(map);
}
void
cry_test_maps(void)
{
cry_unittest_run("structures.map.initialization", test_map_init, 0, 10);
cry_unittest_run("structures.map.lookup", test_map_lookup, 0, 10);
cry_unittest_run("structures.map.removal", test_map_removal, 0, 10);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment