Add filter tests
authorMaciej Piechotka <uzytkownik2@gmail.com>
Wed, 17 Aug 2011 20:42:56 +0000 (21:42 +0100)
committerMaciej Piechotka <uzytkownik2@gmail.com>
Wed, 17 Aug 2011 20:42:56 +0000 (21:42 +0100)
tests/testcollection.vala

index 246b94b..fa5304d 100644 (file)
@@ -49,6 +49,7 @@ public abstract class CollectionTests : Gee.TestCase {
                add_test ("[Collection] foreach", test_foreach);
                add_test ("[Collection] map", test_map);
                add_test ("[Collection] scan", test_scan);
+               add_test ("[Collection] filter", test_filter);
        }
 
        protected Collection<string> test_collection;
@@ -863,5 +864,41 @@ public abstract class CollectionTests : Gee.TestCase {
                assert (two);
                assert (three);
        }
+
+       public void test_filter () {
+               assert (test_collection.add ("one"));
+               assert (test_collection.add ("two"));
+               assert (test_collection.add ("three"));
+
+               bool one = false;
+               bool two = false;
+               bool three = false;
+
+               var iter = test_collection.iterator().filter ((str) => {
+                       if (str == "one") {
+                               assert (!one);
+                               one = true;
+                       } else if (str == "two") {
+                               assert (!two);
+                               two = true;
+                       } else if (str == "three") {
+                               assert (!three);
+                               three = true;
+                       } else {
+                               assert_not_reached ();
+                       }
+                       return str != "two";
+               });
+
+               assert (!iter.valid);
+
+               int j = 0;
+               while (iter.next ())
+                       j++;
+               assert (j == 2);
+               assert (one);
+               assert (two);
+               assert (three);
+       }
 }