diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-01 21:25:11 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-01 21:25:11 -0600 |
| commit | db7f5fa764bed00f26bd522758772b610a4f08ef (patch) | |
| tree | 7840d54e29d2d14b709fac8ded648878e8bb3c21 /src/02/04/hash_test.c | |
| parent | c04295209d4bebf82e8d2b9b76c978be36b8a3fa (diff) | |
Build a hacky hash table
Diffstat (limited to 'src/02/04/hash_test.c')
| -rw-r--r-- | src/02/04/hash_test.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/02/04/hash_test.c b/src/02/04/hash_test.c index 6eeaebd..9073897 100644 --- a/src/02/04/hash_test.c +++ b/src/02/04/hash_test.c @@ -12,10 +12,27 @@ Ensure(HashTable, when_initializing_a_hash) { assert_that(hash, is_not_equal_to(NULL)); } +Ensure(HashTable, when_getting_a_value_for_a_key_that_has_not_been_inserted) { + Hash *hash = hash_init(13); + + assert_that(hash_get(hash, 1), is_equal_to(NULL)); +} + +Ensure(HashTable, when_getting_a_values_for_a_key_that_has_been_inserted) { + int key = 7; + int value = 100; + Hash *hash = hash_init(13); + + hash_set(hash, key, value); + assert_that(hash_get(hash, key), is_equal_to(value)); +} + TestSuite *hash_table_tests() { TestSuite *suite = create_test_suite(); add_test_with_context(suite, HashTable, when_initializing_a_hash); + add_test_with_context(suite, HashTable, when_getting_a_value_for_a_key_that_has_not_been_inserted); + add_test_with_context(suite, HashTable, when_getting_a_values_for_a_key_that_has_been_inserted); return suite; } |
