mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
27
test/hash_map_test.c
Normal file
27
test/hash_map_test.c
Normal file
@ -0,0 +1,27 @@
|
||||
#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"));
|
||||
}
|
12
test/hash_map_test.h
Normal file
12
test/hash_map_test.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef __HASH_MAP_TEST__
|
||||
#define __HASH_MAP_TEST__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
|
||||
void hash_map_test();
|
||||
|
||||
#endif
|
@ -5,6 +5,7 @@
|
||||
#include "character_test.h"
|
||||
#include "convert_test.h"
|
||||
#include "dictionary_test.h"
|
||||
#include "hash_map_test.h"
|
||||
#include "linked_list_test.h"
|
||||
#include "mathematics_test.h"
|
||||
#include "queue_test.h"
|
||||
@ -16,6 +17,7 @@ int main() {
|
||||
character_test();
|
||||
convert_test();
|
||||
dictionary_test();
|
||||
hash_map_test();
|
||||
linked_list_test();
|
||||
mathematics_test();
|
||||
queue_test();
|
||||
|
Reference in New Issue
Block a user