summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2011-03-24 13:19:12 +0000
committerPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-16 14:43:40 +0100
commit858e80d7649ebe7af0553531a940098f6d3c8449 (patch)
treeb301494fa50f39f1370b34d7279f5f88cbcc43ed
parent61ed5af3594831015fd52cf4c548ff1840ec334f (diff)
Add navigation tests for LinkedHashSet.Iterator
Helps: bgo#645684
-rw-r--r--tests/folks/linked-hash-set.vala59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/folks/linked-hash-set.vala b/tests/folks/linked-hash-set.vala
index 2e205a8..b52f20a 100644
--- a/tests/folks/linked-hash-set.vala
+++ b/tests/folks/linked-hash-set.vala
@@ -12,6 +12,8 @@ public class LinkedHashSetTests : Folks.TestCase
this.add_test ("bgo640551", this.test_bgo640551);
this.add_test ("iterator", this.test_iterator);
this.add_test ("iterator removal", this.test_iterator_removal);
+ this.add_test ("iterator empty", this.test_iterator_empty);
+ this.add_test ("iterator navigation", this.test_iterator_navigation);
}
public override void set_up ()
@@ -330,6 +332,63 @@ public class LinkedHashSetTests : Folks.TestCase
for (var i = 0; i < 10; i++)
assert (!lhs.contains (i));
}
+
+ public void test_iterator_empty ()
+ {
+ LinkedHashSet<int> lhs = new LinkedHashSet<int> ();
+ var _iter = lhs.iterator ();
+ assert (_iter is BidirIterator);
+ var iter = (BidirIterator<int>) _iter;
+
+ /* Check the iterator behaves correctly for an empty LinkedHashSet */
+ assert (!iter.next ());
+ assert (!iter.has_next ());
+ assert (!iter.first ());
+ assert (!iter.previous ());
+ assert (!iter.has_previous ());
+ assert (!iter.last ());
+ }
+
+ public void test_iterator_navigation ()
+ {
+ LinkedHashSet<int> lhs = new LinkedHashSet<int> ();
+
+ lhs.add (0);
+ lhs.add (1);
+ lhs.add (2);
+
+ var _iter = lhs.iterator ();
+ assert (_iter is BidirIterator);
+ var iter = (BidirIterator<int>) _iter;
+
+ assert (iter.has_next ());
+ assert (!iter.has_previous ());
+ assert (iter.next ());
+ assert (iter.get () == 0);
+
+ assert (iter.first ());
+ assert (iter.get () == 0);
+
+ assert (iter.has_next ());
+ assert (iter.next ());
+ assert (iter.has_previous ());
+ assert (iter.get () == 1);
+
+ assert (iter.first ());
+ assert (iter.get () == 0);
+
+ assert (iter.next ());
+ assert (iter.next ());
+ assert (iter.get () == 2);
+ assert (!iter.has_next ());
+ assert (iter.has_previous ());
+
+ assert (iter.last ());
+ assert (iter.get () == 2);
+
+ assert (iter.previous ());
+ assert (iter.get () == 1);
+ }
}
public int main (string[] args)