[folks] Add tests for LinkedHashSet.iterator()



commit c6f44b505999d259af5b262a69e57da31af611d0
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Mar 24 11:57:24 2011 +0000

    Add tests for LinkedHashSet.iterator()
    
    Helps: bgo#645684

 tests/folks/linked-hash-set.vala |   49 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/tests/folks/linked-hash-set.vala b/tests/folks/linked-hash-set.vala
index fcb472a..2e205a8 100644
--- a/tests/folks/linked-hash-set.vala
+++ b/tests/folks/linked-hash-set.vala
@@ -10,6 +10,8 @@ public class LinkedHashSetTests : Folks.TestCase
       this.add_test ("list properties", this.test_list_properties);
       this.add_test ("object elements", this.test_object_elements);
       this.add_test ("bgo640551", this.test_bgo640551);
+      this.add_test ("iterator", this.test_iterator);
+      this.add_test ("iterator removal", this.test_iterator_removal);
     }
 
   public override void set_up ()
@@ -281,6 +283,53 @@ public class LinkedHashSetTests : Folks.TestCase
           im_set.add_all (cur_addresses);
         });
     }
+
+  /* Test that LinkedHashSet.iterator() works at a basic level */
+  public void test_iterator ()
+    {
+      HashSet<int> values = new HashSet<int> ();
+      LinkedHashSet<int> lhs = new LinkedHashSet<int> ();
+
+      /* Set up the values and insert them into the HashSet */
+      for (var i = 0; i < 10; i++)
+        {
+          values.add (i);
+          lhs.add (i);
+        }
+
+      /* We don't make any assertions about the order; just that exactly the
+       * right set of values is returned by the iterator. */
+      var iter = lhs.iterator ();
+
+      while (iter.next ())
+        {
+          var i = iter.get ();
+          assert (values.remove (i));
+        }
+
+      assert (values.size == 0);
+    }
+
+  public void test_iterator_removal ()
+    {
+      LinkedHashSet<int> lhs = new LinkedHashSet<int> ();
+
+      /* Set up the values and insert them into the HashSet */
+      for (var i = 0; i < 10; i++)
+        lhs.add (i);
+
+      /* Remove all the entries from the LinkedHashSet via Iterator.remove().
+       * Then, check that they've been removed. */
+      var iter = lhs.iterator ();
+
+      while (iter.next ())
+        iter.remove ();
+
+      assert (lhs.size == 0);
+
+      for (var i = 0; i < 10; i++)
+        assert (!lhs.contains (i));
+    }
 }
 
 public int main (string[] args)



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