[libgee] Enhance multimap's tests
- From: Didier Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Enhance multimap's tests
- Date: Mon, 28 Sep 2009 14:35:08 +0000 (UTC)
commit 29c47b2c44cefd3e991ce5c0df11f80e91bee8d5
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Mon Sep 28 13:33:54 2009 +0200
Enhance multimap's tests
tests/testmultimap.vala | 112 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/tests/testmultimap.vala b/tests/testmultimap.vala
index 2007caa..7a2f9e0 100644
--- a/tests/testmultimap.vala
+++ b/tests/testmultimap.vala
@@ -32,6 +32,7 @@ public abstract class MultiMapTests : Gee.TestCase {
base (name);
add_test ("[MultiMap] size", test_size);
add_test ("[MultiMap] getting and setting", test_getting_setting);
+ add_test ("[MultiMap] keys, all keys and values", test_keys_all_keys_values);
}
protected MultiMap<string,string> test_multi_map;
@@ -61,6 +62,7 @@ public abstract class MultiMapTests : Gee.TestCase {
assert (test_multi_map != null);
test_multi_map.set ("0", "0");
+ assert (test_multi_map.contains ("0"));
assert (test_multi_map.get ("0").size == 1);
assert (test_multi_map.get ("0").contains ("0"));
@@ -72,10 +74,120 @@ public abstract class MultiMapTests : Gee.TestCase {
assert (test_multi_map.get ("0").contains ("1"));
test_multi_map.set ("1", "1");
+ assert (test_multi_map.contains ("1"));
assert (test_multi_map.get ("0").size == 2);
assert (test_multi_map.get ("0").contains ("0"));
assert (test_multi_map.get ("0").contains ("1"));
assert (test_multi_map.get ("1").size == 1);
assert (test_multi_map.get ("0").contains ("1"));
+
+ // Check remove if bindings exist
+ assert (test_multi_map.remove ("0", "0"));
+ assert (test_multi_map.contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("0"));
+ assert (test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("1").contains ("1"));
+
+ // Check remove if only one binding exists
+ assert (test_multi_map.remove ("0", "1"));
+ assert (! test_multi_map.contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("1").contains ("1"));
+
+ // Check remove if no binding exists
+ assert (! test_multi_map.remove ("0", "1"));
+ assert (! test_multi_map.contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("1").contains ("1"));
+
+ test_multi_map.clear ();
+ assert (! test_multi_map.contains ("0"));
+ assert (! test_multi_map.contains ("1"));
+
+ // Check remove_all
+ test_multi_map.set ("0", "0");
+ test_multi_map.set ("0", "1");
+ test_multi_map.set ("1", "1");
+ assert (test_multi_map.size == 3);
+
+ assert (test_multi_map.contains ("0"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("0").size == 2);
+ assert (test_multi_map.get ("0").contains ("0"));
+ assert (test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.get ("1").size == 1);
+ assert (test_multi_map.get ("0").contains ("1"));
+
+ // Check remove_all if bindings exist
+ assert (test_multi_map.remove_all ("0"));
+ assert (! test_multi_map.contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("1").contains ("1"));
+
+ // Check remove_all if no binding exists
+ assert (! test_multi_map.remove_all ("0"));
+ assert (! test_multi_map.contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("0"));
+ assert (! test_multi_map.get ("0").contains ("1"));
+ assert (test_multi_map.contains ("1"));
+ assert (test_multi_map.get ("1").contains ("1"));
+ }
+
+ private void test_keys_all_keys_values () {
+ // Check the map exists
+ assert (test_multi_map != null);
+
+ test_multi_map.set ("0", "0");
+ test_multi_map.set ("0", "1");
+ test_multi_map.set ("1", "1");
+
+ // Check for keys, all_keys and values
+ Set<string> keys = test_multi_map.get_keys ();
+ MultiSet<string> all_keys = test_multi_map.get_all_keys ();
+ Collection<string> values = test_multi_map.get_values ();
+
+ assert (keys.contains ("0"));
+ assert (keys.contains ("1"));
+ assert (all_keys.count ("0") == 2);
+ assert (all_keys.count ("1") == 1);
+ assert (values.contains ("0"));
+ assert (values.contains ("1"));
+
+ bool zero_found = false;
+ bool zero_found_once = true;
+ bool one_found = false;
+ bool one_found_twice = false;
+ bool nothing_more = true;
+ foreach (string value in values) {
+ if (value == "0") {
+ if (zero_found) {
+ zero_found_once = false;
+ }
+ zero_found = true;
+ } else if (value == "1") {
+ if (one_found) {
+ if (one_found_twice) {
+ one_found_twice = false;
+ } else {
+ one_found_twice = true;
+ }
+ }
+ one_found = true;
+ } else {
+ nothing_more = false;
+ }
+ }
+ assert (zero_found);
+ assert (zero_found_once);
+ assert (one_found);
+ assert (one_found_twice);
+ assert (nothing_more);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]