From 3bf3ca9b3aede625fdc818e01ad0128db7cce9f6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 3 Aug 2020 15:36:23 -0600 Subject: Add a spec to insert each value in question --- src/02/04/hash_test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/02') diff --git a/src/02/04/hash_test.c b/src/02/04/hash_test.c index 88ad925..5f7b2ad 100644 --- a/src/02/04/hash_test.c +++ b/src/02/04/hash_test.c @@ -36,6 +36,22 @@ Ensure(HashTable, when_a_hash_collision_occurs) { assert_that(hash_get(hash, 21), is_equal_to(210)); } +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}; + + for (int i = 0; i < sizeof(items); i++) { + int value = i * 10; + hash_set(hash, items[i], &value); + } + + for (int i = 0; i < sizeof(items); i++) { + int key = items[i]; + assert_that(hash_get(hash, key), is_equal_to(key * 10)); + } +} + TestSuite *hash_table_tests() { TestSuite *suite = create_test_suite(); -- cgit v1.2.3