summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2013-10-25 13:38:38 -0700
committerEric Anholt <eric@anholt.net>2013-10-25 15:29:09 -0700
commit5594ed57413bf0117c592cf8edc8c9363b98a578 (patch)
treeeb91118aaee8acb55d2356f0047aa9f4f7d5ecd0 /tests
parent9dd53079a431768b76431fa632a5ea086d0c54e9 (diff)
Add set_contains and int_set_contains functions.
These are convenience functions on top of set_search and int_set_search. With a set, containment is often the most important notion of interest, and it helps to be able to query this without needing to declare a local struct set_entry*. v2: Whitespace consistency (changes by anholt)
Diffstat (limited to 'tests')
-rw-r--r--tests/int-set/delete_and_lookup.c6
-rw-r--r--tests/int-set/delete_management.c1
-rw-r--r--tests/int-set/insert_and_lookup.c2
-rw-r--r--tests/int-set/insert_many.c1
-rw-r--r--tests/int-set/replacement.c2
-rw-r--r--tests/set/delete_and_lookup.c6
-rw-r--r--tests/set/delete_management.c1
-rw-r--r--tests/set/insert_and_lookup.c2
-rw-r--r--tests/set/insert_many.c1
-rw-r--r--tests/set/replacement.c2
10 files changed, 24 insertions, 0 deletions
diff --git a/tests/int-set/delete_and_lookup.c b/tests/int-set/delete_and_lookup.c
index f37cd0f..5cc3fb8 100644
--- a/tests/int-set/delete_and_lookup.c
+++ b/tests/int-set/delete_and_lookup.c
@@ -51,24 +51,30 @@ main(int argc, char **argv)
int_set_add(set, value2);
int_set_add(set, value3);
+ assert(int_set_contains(set, value3));
entry = int_set_search(set, value3);
assert(entry->value == value3);
+ assert(int_set_contains(set, value2));
entry = int_set_search(set, value2);
assert(entry->value == value2);
+ assert(int_set_contains(set, value1));
entry = int_set_search(set, value1);
assert(entry->value == value1);
int_set_remove_entry(set, entry);
int_set_remove(set, value2);
+ assert(!int_set_contains(set, value1));
entry = int_set_search(set, value1);
assert(entry == NULL);
+ assert(!int_set_contains(set, value2));
entry = int_set_search(set, value2);
assert(entry == NULL);
+ assert(int_set_contains(set, value3));
entry = int_set_search(set, value3);
assert(entry->value == value3);
diff --git a/tests/int-set/delete_management.c b/tests/int-set/delete_management.c
index 0d4bfe3..93f7cf8 100644
--- a/tests/int-set/delete_management.c
+++ b/tests/int-set/delete_management.c
@@ -52,6 +52,7 @@ main(int argc, char **argv)
/* Make sure that all our entries were present at the end. */
for (i = size - 100; i < size; i++) {
+ assert(int_set_contains(set, i));
entry = int_set_search(set, i);
assert(entry);
assert(entry->value == i);
diff --git a/tests/int-set/insert_and_lookup.c b/tests/int-set/insert_and_lookup.c
index 575aac7..ea68321 100644
--- a/tests/int-set/insert_and_lookup.c
+++ b/tests/int-set/insert_and_lookup.c
@@ -44,9 +44,11 @@ main(int argc, char **argv)
int_set_add(set, value1);
int_set_add(set, value2);
+ assert(int_set_contains(set, value1));
entry = int_set_search(set, value1);
assert(entry->value == value1);
+ assert(int_set_contains(set, value2));
entry = int_set_search(set, value2);
assert(entry->value == value2);
diff --git a/tests/int-set/insert_many.c b/tests/int-set/insert_many.c
index 99ad9ea..4c06394 100644
--- a/tests/int-set/insert_many.c
+++ b/tests/int-set/insert_many.c
@@ -46,6 +46,7 @@ main(int argc, char **argv)
}
for (i = 0; i < size; i++) {
+ assert(int_set_contains(set, i));
entry = int_set_search(set, i);
assert(entry);
assert(entry->value == i);
diff --git a/tests/int-set/replacement.c b/tests/int-set/replacement.c
index ef9faaa..011a9a4 100644
--- a/tests/int-set/replacement.c
+++ b/tests/int-set/replacement.c
@@ -43,12 +43,14 @@ main(int argc, char **argv)
int_set_add(set, value);
int_set_add(set, value);
+ assert(int_set_contains(set, value));
entry = int_set_search(set, value);
assert(entry);
assert(entry->value == value);
int_set_remove_entry(set, entry);
+ assert(!int_set_contains(set, value));
entry = int_set_search(set, value);
assert(!entry);
diff --git a/tests/set/delete_and_lookup.c b/tests/set/delete_and_lookup.c
index 6ad6209..93d3bc7 100644
--- a/tests/set/delete_and_lookup.c
+++ b/tests/set/delete_and_lookup.c
@@ -58,24 +58,30 @@ main(int argc, char **argv)
set_add(set, hash_str2, str2);
set_add(set, hash_str2, str3);
+ assert(set_contains(set, hash_str3, str3));
entry = set_search(set, hash_str3, str3);
assert(strcmp(entry->key, str3) == 0);
+ assert(set_contains(set, hash_str2, str2));
entry = set_search(set, hash_str2, str2);
assert(strcmp(entry->key, str2) == 0);
+ assert(set_contains(set, hash_str1, str1));
entry = set_search(set, hash_str1, str1);
assert(strcmp(entry->key, str1) == 0);
set_remove_entry(set, entry);
set_remove(set, hash_str2, str2);
+ assert(!set_contains(set, hash_str1, str1));
entry = set_search(set, hash_str1, str1);
assert(entry == NULL);
+ assert(!set_contains(set, hash_str2, str2));
entry = set_search(set, hash_str2, str2);
assert(entry == NULL);
+ assert(set_contains(set, hash_str3, str3));
entry = set_search(set, hash_str3, str3);
assert(strcmp(entry->key, str3) == 0);
diff --git a/tests/set/delete_management.c b/tests/set/delete_management.c
index f54c9c5..14f1fe1 100644
--- a/tests/set/delete_management.c
+++ b/tests/set/delete_management.c
@@ -67,6 +67,7 @@ main(int argc, char **argv)
/* Make sure that all our entries were present at the end. */
for (i = size - 100; i < size; i++) {
+ assert(set_contains(set, i, &keys[i]));
entry = set_search(set, i, &keys[i]);
assert(entry);
assert(key_value(entry->key) == i);
diff --git a/tests/set/insert_and_lookup.c b/tests/set/insert_and_lookup.c
index 367daac..6b01bdd 100644
--- a/tests/set/insert_and_lookup.c
+++ b/tests/set/insert_and_lookup.c
@@ -46,9 +46,11 @@ main(int argc, char **argv)
set_add(set, hash_str1, str1);
set_add(set, hash_str2, str2);
+ assert(set_contains(set, hash_str1, str1));
entry = set_search(set, hash_str1, str1);
assert(strcmp(entry->key, str1) == 0);
+ assert(set_contains(set, hash_str2, str2));
entry = set_search(set, hash_str2, str2);
assert(strcmp(entry->key, str2) == 0);
diff --git a/tests/set/insert_many.c b/tests/set/insert_many.c
index 4c8dfd0..2dc15da 100644
--- a/tests/set/insert_many.c
+++ b/tests/set/insert_many.c
@@ -61,6 +61,7 @@ main(int argc, char **argv)
}
for (i = 0; i < size; i++) {
+ assert(set_contains(set, i, keys + i));
entry = set_search(set, i, keys + i);
assert(entry);
assert(key_value(entry->key) == i);
diff --git a/tests/set/replacement.c b/tests/set/replacement.c
index 8723ecb..2c7555e 100644
--- a/tests/set/replacement.c
+++ b/tests/set/replacement.c
@@ -46,12 +46,14 @@ main(int argc, char **argv)
set_add(set, hash_str1, str1);
set_add(set, hash_str2, str2);
+ assert(set_contains(set, hash_str1, str1));
entry = set_search(set, hash_str1, str1);
assert(entry);
assert(entry->key == str2);
set_remove_entry(set, entry);
+ assert(!set_contains(set, hash_str1, str1));
entry = set_search(set, hash_str1, str1);
assert(!entry);