summaryrefslogtreecommitdiff
authorDustin Frisch <dustin@dustin-frisch.de>2011-05-24 21:03:03 (GMT)
committer Dustin Frisch <dustin@dustin-frisch.de>2011-05-24 21:03:03 (GMT)
commit368c8a01af1f7a27896b503c47f8c8180cb220ec (patch) (side-by-side diff)
tree54a265aa9fb126f2cf2f1016388c021b188864b0
parent7b96747c5904e92abc9cece28d5484fc31c4d249 (diff)
downloadadt-master.zip
adt-master.tar.gz
Hash Map tests addedHEADmaster
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/map/hash_map.c3
-rw-r--r--test/lists.c2
-rw-r--r--test/maps.c73
3 files changed, 38 insertions, 40 deletions
diff --git a/src/map/hash_map.c b/src/map/hash_map.c
index 271c5a1..e96521c 100644
--- a/src/map/hash_map.c
+++ b/src/map/hash_map.c
@@ -34,7 +34,8 @@ typedef struct hash_map {
/**
* The comparing function used to compare keys.
- */bool (*compare)(const void* key1, const void* key2);
+ */
+ bool (*compare)(const void* key1, const void* key2);
/**
* The number of elements in the map.
diff --git a/test/lists.c b/test/lists.c
index 40cbab4..2778bb3 100644
--- a/test/lists.c
+++ b/test/lists.c
@@ -4,7 +4,7 @@
void test_list(list_t* list) {
iterator_t* it;
- CUTS_ASSERT_CMP("list_size(0)", 0, list_size(list));
+
CUTS_ASSERT_TRUE("list_is_empty(0)", list_is_empty(list));
// Add some elements
diff --git a/test/maps.c b/test/maps.c
index c75b7e3..4f27631 100644
--- a/test/maps.c
+++ b/test/maps.c
@@ -10,45 +10,45 @@ void test_map(map_t* map) {
CUTS_ASSERT_TRUE("map_is_empty(0)", map_is_empty(map));
// Add some elements
- list_add(list, "foo");
- CUTS_ASSERT_CMP("list_size(1)", 1, list_size(list));
- CUTS_ASSERT_FALSE("list_is_empty(1)", list_is_empty(list));
+ map_put(map, "foo", "aaaaa");
+ CUTS_ASSERT_CMP("map_size(1)", 1, map_size(map));
+ CUTS_ASSERT_FALSE("map_is_empty(1)", map_is_empty(map));
- list_add(list, "bar");
- CUTS_ASSERT_CMP("list_size(2)", 2, list_size(list));
- CUTS_ASSERT_FALSE("list_is_empty(2)", list_is_empty(list));
+ map_put(map, "bar", "bbbbbbbbbbb");
+ CUTS_ASSERT_CMP("map_size(2)", 2, map_size(map));
+ CUTS_ASSERT_FALSE("map_is_empty(2)", map_is_empty(map));
- list_add(list, "baz");
- CUTS_ASSERT_CMP("list_size(3)", 3, list_size(list));
- CUTS_ASSERT_FALSE("list_is_empty(3)", list_is_empty(list));
+ map_put(map, "baz", "cc");
+ CUTS_ASSERT_CMP("map_size(3)", 3, map_size(map));
+ CUTS_ASSERT_FALSE("map_is_empty(3)", map_is_empty(map));
- list_add_at(list, 2, "bla");
- CUTS_ASSERT_CMP("list_size(4)", 4, list_size(list));
- CUTS_ASSERT_FALSE("list_is_empty(4)", list_is_empty(list));
+ map_put(map, "bla", NULL);
+ CUTS_ASSERT_CMP("map_size(4)", 4, map_size(map));
+ CUTS_ASSERT_FALSE("map_is_empty(4)", map_is_empty(map));
// Fetch elements
- CUTS_ASSERT_STRCMP("list_get(0)", "foo", (const char*) list_get(list, 0));
- CUTS_ASSERT_STRCMP("list_get(1)", "bar", (const char*) list_get(list, 1));
- CUTS_ASSERT_STRCMP("list_get(2)", "bla", (const char*) list_get(list, 2));
- CUTS_ASSERT_STRCMP("list_get(3)", "baz", (const char*) list_get(list, 3));
+ CUTS_ASSERT_STRCMP("map_get(0)", "aaaaa", (const char*) map_get(map, "foo"));
+ CUTS_ASSERT_STRCMP("map_get(1)", "bbbbbbbbbbb", (const char*) map_get(map, "bar"));
+ CUTS_ASSERT_STRCMP("map_get(2)", "cc", (const char*) map_get(map, "bla"));
+ CUTS_ASSERT_STRCMP("map_get(3)", NULL, (const char*) map_get(map, "baz"));
// Remove element
- list_remove_at(list, 2);
- CUTS_ASSERT_CMP("list_size(5)", 3, list_size(list));
- CUTS_ASSERT_FALSE("list_is_empty(5)", list_is_empty(list));
+ map_remove(map, "bla");
+ CUTS_ASSERT_CMP("map_size(5)", 3, map_size(map));
+ CUTS_ASSERT_FALSE("map_is_empty(5)", map_is_empty(map));
// Iterate elements
- it = list_iterator(list);
- CUTS_ASSERT_TRUE("iterator_has_next(0)", iterator_has_next(it));
- CUTS_ASSERT_STRCMP("iterator_next(0)", "foo", (const char*) iterator_next(it));
-
- CUTS_ASSERT_TRUE("iterator_has_next(1)", iterator_has_next(it));
- CUTS_ASSERT_STRCMP("iterator_next(1)", "bar", (const char*) iterator_next(it));
-
- CUTS_ASSERT_TRUE("iterator_has_next(2)", iterator_has_next(it));
- CUTS_ASSERT_STRCMP("iterator_next(2)", "baz", (const char*) iterator_next(it));
-
- CUTS_ASSERT_FALSE("iterator_has_next(3)", iterator_has_next(it));
+// it = list_iterator(list);
+// CUTS_ASSERT_TRUE("iterator_has_next(0)", iterator_has_next(it));
+// CUTS_ASSERT_STRCMP("iterator_next(0)", "foo", (const char*) iterator_next(it));
+//
+// CUTS_ASSERT_TRUE("iterator_has_next(1)", iterator_has_next(it));
+// CUTS_ASSERT_STRCMP("iterator_next(1)", "bar", (const char*) iterator_next(it));
+//
+// CUTS_ASSERT_TRUE("iterator_has_next(2)", iterator_has_next(it));
+// CUTS_ASSERT_STRCMP("iterator_next(2)", "baz", (const char*) iterator_next(it));
+//
+// CUTS_ASSERT_FALSE("iterator_has_next(3)", iterator_has_next(it));
// Clear
map_clear(map);
@@ -56,14 +56,11 @@ void test_map(map_t* map) {
CUTS_ASSERT_TRUE("map_is_empty(6)", map_is_empty(map));
// Destroy map
- list_destroy(map);
+ map_destroy(map);
}
-CUTS_TEST(linked_list) { test_list(linked_list_new()); }
-
-CUTS_TEST(array_list_10) { test_list(array_list_new(10)); }
-CUTS_TEST(array_list_5) { test_list(array_list_new(5)); }
-CUTS_TEST(array_list_4) { test_list(array_list_new(4)); }
-CUTS_TEST(array_list_3) { test_list(array_list_new(3)); }
-CUTS_TEST(array_list_1) { test_list(array_list_new(1)); }
+CUTS_TEST(hash_map_10) { test_map(hash_map_new(hash, compare, 10)); }
+CUTS_TEST(hash_map_3) { test_map(hash_map_new(hash, compare, 3)); }
+CUTS_TEST(hash_map_5) { test_map(hash_map_new(hash, compare, 5)); }
+CUTS_TEST(hash_map_1) { test_map(hash_map_new(hash, compare, 1)); }