diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-03 15:49:36 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-03 15:49:36 -0600 |
| commit | 8b6d6e4756008d412bd5daf3db44f3537deacd3f (patch) | |
| tree | dc06b9839087b36db120c4ddcd6abb1af7a25f99 /src/02/04/hash_test.c | |
| parent | 3bf3ca9b3aede625fdc818e01ad0128db7cce9f6 (diff) | |
Create program to display hash table
Diffstat (limited to 'src/02/04/hash_test.c')
| -rw-r--r-- | src/02/04/hash_test.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/02/04/hash_test.c b/src/02/04/hash_test.c index 5f7b2ad..b10e9e1 100644 --- a/src/02/04/hash_test.c +++ b/src/02/04/hash_test.c @@ -38,15 +38,16 @@ Ensure(HashTable, when_a_hash_collision_occurs) { Ensure(HashTable, when_inserting_multiple_items_into_the_hash_table) { Hash *hash = hash_init(13); - int items[] = {1, 5, 21, 26, 39, 14, 15, 16, 17, 18, 19, 20, 111, 145, 146}; + int n = sizeof(items) / sizeof(int); - for (int i = 0; i < sizeof(items); i++) { - int value = i * 10; - hash_set(hash, items[i], &value); + for (int i = 0; i < n; i++) { + int key = items[i]; + long value = key * 10; + hash_set(hash, key, (void *)value); } - for (int i = 0; i < sizeof(items); i++) { + for (int i = 0; i < n; i++) { int key = items[i]; assert_that(hash_get(hash, key), is_equal_to(key * 10)); } @@ -62,6 +63,7 @@ TestSuite *hash_table_tests() { add_test_with_context(suite, HashTable, when_getting_a_values_for_a_key_that_has_been_inserted); add_test_with_context(suite, HashTable, when_a_hash_collision_occurs); + add_test_with_context(suite, HashTable, when_inserting_multiple_items_into_the_hash_table); return suite; } |
