summaryrefslogtreecommitdiffstats
path: root/libdimension/tests/dictionary.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2012-12-19 10:50:24 -0500
committerTavian Barnes <tavianator@tavianator.com>2012-12-19 10:50:24 -0500
commitd3f1ddfab0299d4d0b0259a363d6d639dc862b88 (patch)
tree618f7920798ab6a113e6f4cc5efe526455585747 /libdimension/tests/dictionary.c
parentde46e306721643c6ba845829018a83457adb3aba (diff)
downloaddimension-d3f1ddfab0299d4d0b0259a363d6d639dc862b88.tar.xz
Add more dictionary tests.
Diffstat (limited to 'libdimension/tests/dictionary.c')
-rw-r--r--libdimension/tests/dictionary.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/libdimension/tests/dictionary.c b/libdimension/tests/dictionary.c
index 63969d3..ca0c6b0 100644
--- a/libdimension/tests/dictionary.c
+++ b/libdimension/tests/dictionary.c
@@ -62,20 +62,39 @@ DMNSN_TEST(dictionary, insert_and_get)
ck_assert_int_eq(*value_at, value_in);
}
+DMNSN_TEST(dictionary, insert_multiple)
+{
+ const int value1 = 123, value2 = 456, value3 = 789;
+ int value_out;
+
+ dmnsn_dictionary_insert(dict, "key1", &value1);
+ dmnsn_dictionary_insert(dict, "key2", &value2);
+ dmnsn_dictionary_insert(dict, "asdf", &value3);
+
+ ck_assert(dmnsn_dictionary_get(dict, "key1", &value_out));
+ ck_assert_int_eq(value_out, value1);
+
+ ck_assert(dmnsn_dictionary_get(dict, "key2", &value_out));
+ ck_assert_int_eq(value_out, value2);
+
+ ck_assert(dmnsn_dictionary_get(dict, "asdf", &value_out));
+ ck_assert_int_eq(value_out, value3);
+}
+
DMNSN_TEST(dictionary, insert_overwrites)
{
const int value1 = 123, value2 = 456;
- int value;
+ int value_out;
/* Insert and read back value1 */
dmnsn_dictionary_insert(dict, "key", &value1);
- ck_assert(dmnsn_dictionary_get(dict, "key", &value));
- ck_assert_int_eq(value, value1);
+ ck_assert(dmnsn_dictionary_get(dict, "key", &value_out));
+ ck_assert_int_eq(value_out, value1);
/* Insert and read back value2 */
dmnsn_dictionary_insert(dict, "key", &value2);
- ck_assert(dmnsn_dictionary_get(dict, "key", &value));
- ck_assert_int_eq(value, value2);
+ ck_assert(dmnsn_dictionary_get(dict, "key", &value_out));
+ ck_assert_int_eq(value_out, value2);
}
DMNSN_TEST(dictionary, remove)
@@ -91,3 +110,23 @@ DMNSN_TEST(dictionary, remove)
int *value_at = dmnsn_dictionary_at(dict, "key");
ck_assert(value_at == NULL);
}
+
+static int sum = 0;
+
+static void
+dmnsn_dictionary_test_apply_callback(void *ptr)
+{
+ sum += *(int *)ptr;
+}
+
+DMNSN_TEST(dictionary, apply)
+{
+ const int value1 = 123, value2 = 456, value3 = 789;
+
+ dmnsn_dictionary_insert(dict, "key1", &value1);
+ dmnsn_dictionary_insert(dict, "key2", &value2);
+ dmnsn_dictionary_insert(dict, "asdf", &value3);
+
+ dmnsn_dictionary_apply(dict, dmnsn_dictionary_test_apply_callback);
+ ck_assert_int_eq(sum, value1 + value2 + value3);
+}