Commit ff39d2be authored by Chris Müller's avatar Chris Müller

test: add testcode for maps.

parent d9216f73
......@@ -3,6 +3,7 @@ set(TEST crystal_unittests)
set(SOURCES
main.c
array.c
map.c
structures.c
)
......
......@@ -3,6 +3,7 @@
void cry_test_structures();
void cry_test_arrays();
void cry_test_maps();
int
main(int argc, char** argv)
......@@ -11,6 +12,7 @@ main(int argc, char** argv)
cry_test_structures();
cry_test_arrays();
cry_test_maps();
cry_unittest_finalize();
......
#include "unittest.h"
#include "structures/map.h"
#include <assert.h>
#include <string.h>
static void
test_map_initialization(const_pointer data)
{
struct CryMap* map = cry_map_new(cry_cast(cry_ordering_funptr, strcmp));
assert(cry_map_size(map) == 0);
assert(cry_map_lookup(map, "unknown_key") == 0);
cry_map_free(map, 0, 0);
}
static void
test_map_insertion(const_pointer data)
{
struct CryMap* map = cry_map_new(cry_cast(cry_ordering_funptr, strcmp));
const char** keys = cry_cast(const char**, data);
assert(cry_map_size(map) == 0);
while(*keys != 0) {
assert(cry_map_insert(map, *keys, *keys) == CRY_OKAY);
++keys;
}
assert(cry_map_size(map) == 7);
assert(cry_map_lookup(map, "A") != 0);
assert(strcmp(cry_cast(const char*, cry_map_lookup(map, "A")), "A") == 0);
assert(cry_map_lookup(map, "B") != 0);
assert(strcmp(cry_cast(const char*, cry_map_lookup(map, "B")), "B") == 0);
assert(cry_map_lookup(map, "S") != 0);
assert(strcmp(cry_cast(const char*, cry_map_lookup(map, "S")), "S") == 0);
assert(cry_map_lookup(map, "F") == 0);
cry_map_free(map, 0, 0);
}
void
cry_test_maps(void)
{
const char* keys[] = { "A", "B", "C", "Z", "D", "S", "E", 0 };
cry_unittest_run("structures.map.initialization", test_map_initialization, 0, 10);
cry_unittest_run("structures.map.insertion", test_map_insertion, keys, 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