[libgee] Add more add and remove tests



commit e174bec0c1900618c934cf192f2640764e8e3975
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sat Sep 26 07:14:06 2009 +0200

    Add more add and remove tests

 tests/testcollection.vala |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index ebb88bc..b96654a 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -35,6 +35,7 @@ public abstract class CollectionTests : Gee.TestCase {
 		add_test ("[Collection] mutable iterator", test_mutable_iterator);
 		add_test ("[Collection] contains, size and is_empty",
 		          test_contains_size_and_is_empty);
+		add_test ("[Collection] add and remove", test_add_remove);
 		add_test ("[Collection] add_all", test_add_all);
 		add_test ("[Collection] contains_all", test_contains_all);
 		add_test ("[Collection] remove_all", test_remove_all);
@@ -330,6 +331,43 @@ public abstract class CollectionTests : Gee.TestCase {
 		assert (test_collection.is_empty);
 	}
 
+	public void test_add_remove () {
+		// Check the collection exists
+		assert (test_collection != null);
+
+		string[] to_add = {
+			"one", "two", "three", "four", "five", "six", "seven", "eight",
+			"nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
+			"fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty",
+			"twenty one", "twenty two", "twenty three", "twenty four",
+			"twenty five", "twenty six", "twenty seven", "twenty eight",
+			"twenty nine", "thirty", "thirty one", "thirty two", "thirty four",
+			"thirty five", "thirty six", "thirty seven", "thirty eight",
+			"thirty nine", "fourty"
+		};
+		var expected_size = 0;
+
+		foreach (var a in to_add) {
+			assert (!test_collection.contains (a));
+			assert (test_collection.size == expected_size++);
+			assert (test_collection.add (a));
+			assert (test_collection.contains (a));
+		}
+		assert (test_collection.size == to_add.length);
+
+		foreach (var a in to_add) {
+			assert (test_collection.contains (a));
+		}
+
+		foreach (var a in to_add) {
+			assert (test_collection.contains (a));
+			assert (test_collection.size == expected_size--);
+			assert (test_collection.remove (a));
+			assert (!test_collection.contains (a));
+		}
+		assert (test_collection.size == 0);
+	}
+
 	public void test_add_all () {
 		// Check the collection exists
 		assert (test_collection != null);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]