1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-12-11 21:13:00 +01:00
libcproject/test/hash_map_test.c

29 lines
1.2 KiB
C
Raw Normal View History

#include "hash_map_test.h"
void hash_map_test() {
struct hash_map *hash_map = hash_map_initialization();
assert(hash_map->length == 0);
hash_map_add(hash_map, "key", (void *)'a');
hash_map_add(hash_map, "key1", (void *)'b');
hash_map_add(hash_map, "key2", (void *)'c');
hash_map_add(hash_map, "key3", (void *)'d');
hash_map_add(hash_map, "key4", (void *)'e');
hash_map_add(hash_map, "key5", (void *)'f');
assert(hash_map->length == 6);
assert(hash_map_get(hash_map, "key") == (void *)'a');
assert(hash_map_get(hash_map, "key1") == (void *)'b');
assert(hash_map_get(hash_map, "key2") == (void *)'c');
assert(hash_map_get(hash_map, "key3") == (void *)'d');
assert(hash_map_get(hash_map, "key4") == (void *)'e');
assert(hash_map_get(hash_map, "key5") == (void *)'f');
hash_map_add(hash_map, "key5", (void *)'a');
assert(hash_map_get(hash_map, "key5") == (void *)'a');
assert(hash_map_contains_key(hash_map, "key5"));
assert(!hash_map_contains_key(hash_map, "invalid key"));
assert(hash_map_contains_key(hash_map, "key5"));
hash_map_remove(hash_map, "key5");
assert(hash_map->length == 5);
assert(!hash_map_contains_key(hash_map, "key5"));
2023-08-03 23:17:54 +02:00
hash_map_free(hash_map);
}