[libgee] Split List interface into List and BidirList
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Split List interface into List and BidirList
- Date: Sun, 25 Sep 2011 19:31:35 +0000 (UTC)
commit ef7fc9241fe925d5e890e7c98f01aa0f469c4f51
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Wed Mar 30 07:43:26 2011 +0200
Split List interface into List and BidirList
gee/Makefile.am | 4 +
gee/abstractbidirlist.vala | 47 +++++++++++++++
gee/arraylist.vala | 11 +++-
gee/bidirlist.vala | 35 +++++++++++
gee/bidirlistiterator.vala | 29 +++++++++
gee/linkedlist.vala | 11 +++-
gee/listiterator.vala | 8 +--
gee/readonlybidirlist.vala | 73 +++++++++++++++++++++++
gee/readonlylist.vala | 22 +-------
tests/Makefile.am | 2 +
tests/testarraylist.vala | 2 +-
tests/testbidirlist.vala | 107 ++++++++++++++++++++++++++++++++++
tests/testlinkedlist.vala | 2 +-
tests/testlist.vala | 39 +-----------
tests/testmain.vala | 1 +
tests/testreadonlybidirlist.vala | 119 ++++++++++++++++++++++++++++++++++++++
tests/testreadonlylist.vala | 26 ++------
17 files changed, 450 insertions(+), 88 deletions(-)
---
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 90fdf25..cf41f42 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -5,6 +5,7 @@ lib_LTLIBRARIES = \
$(NULL)
libgee_0_8_la_SOURCES = \
+ abstractbidirlist.vala \
abstractcollection.vala \
abstractlist.vala \
abstractmap.vala \
@@ -16,6 +17,8 @@ libgee_0_8_la_SOURCES = \
abstractsortedset.vala \
arraylist.vala \
bidiriterator.vala \
+ bidirlist.vala \
+ bidirlistiterator.vala \
bidirmapiterator.vala \
collection.vala \
comparable.vala \
@@ -39,6 +42,7 @@ libgee_0_8_la_SOURCES = \
multiset.vala \
priorityqueue.vala \
queue.vala \
+ readonlybidirlist.vala \
readonlycollection.vala \
readonlylist.vala \
readonlymap.vala \
diff --git a/gee/abstractbidirlist.vala b/gee/abstractbidirlist.vala
new file mode 100644
index 0000000..5d20951
--- /dev/null
+++ b/gee/abstractbidirlist.vala
@@ -0,0 +1,47 @@
+/* bidirlistiterator.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+
+public abstract class Gee.AbstractBidirList<G> : AbstractList<G>, BidirList<G> {
+
+ /**
+ * { inheritDoc}
+ */
+ public abstract BidirListIterator<G> bidir_list_iterator ();
+
+ private weak BidirList<G> _read_only_view;
+
+ /**
+ * { inheritDoc}
+ */
+ public virtual new BidirList<G> read_only_view {
+ owned get {
+ BidirList<G> instance = _read_only_view;
+ if (_read_only_view == null) {
+ instance = new ReadOnlyBidirList<G> (this);
+ _read_only_view = instance;
+ instance.add_weak_pointer ((void**) (&_read_only_view));
+ }
+ return instance;
+ }
+ }
+}
+
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 69472bf..a051378 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -37,7 +37,7 @@ using GLib;
*
* @see LinkedList
*/
-public class Gee.ArrayList<G> : AbstractList<G> {
+public class Gee.ArrayList<G> : AbstractBidirList<G> {
/**
* { inheritDoc}
*/
@@ -95,6 +95,13 @@ public class Gee.ArrayList<G> : AbstractList<G> {
/**
* { inheritDoc}
*/
+ public override BidirListIterator<G> bidir_list_iterator () {
+ return new Iterator<G> (this);
+ }
+
+ /**
+ * { inheritDoc}
+ */
public override bool contains (G item) {
return (index_of (item) != -1);
}
@@ -256,7 +263,7 @@ public class Gee.ArrayList<G> : AbstractList<G> {
_items.resize (value);
}
- private class Iterator<G> : Object, Traversable<G>, Gee.Iterator<G>, BidirIterator<G>, ListIterator<G> {
+ private class Iterator<G> : Object, Traversable<G>, Gee.Iterator<G>, BidirIterator<G>, ListIterator<G>, BidirListIterator<G> {
private ArrayList<G> _list;
private int _index = -1;
private bool _removed = false;
diff --git a/gee/bidirlist.vala b/gee/bidirlist.vala
new file mode 100644
index 0000000..8d1266b
--- /dev/null
+++ b/gee/bidirlist.vala
@@ -0,0 +1,35 @@
+/* bidirlist.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+
+public interface Gee.BidirList<G> : Gee.List<G> {
+ /**
+ * Returns a BidirListIterator that can be used for iteration over this list.
+ *
+ * @return a BidirListIterator that can be used for iteration over this list
+ */
+ public abstract new BidirListIterator<G> bidir_list_iterator ();
+
+ /**
+ * The read-only view of this list.
+ */
+ public abstract new BidirList<G> read_only_view { owned get; }
+}
diff --git a/gee/bidirlistiterator.vala b/gee/bidirlistiterator.vala
new file mode 100644
index 0000000..0d4bb67
--- /dev/null
+++ b/gee/bidirlistiterator.vala
@@ -0,0 +1,29 @@
+/* bidirlistiterator.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+public interface Gee.BidirListIterator<G> : Gee.BidirIterator<G>, Gee.ListIterator<G> {
+ /**
+ * Inserts the specified item before the current item in the iteration. The
+ * cursor is let to point to the current item.
+ */
+ public abstract void insert (G item);
+}
+
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index 56c24cf..fb8fae5 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -32,7 +32,7 @@
*
* @see ArrayList
*/
-public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
+public class Gee.LinkedList<G> : AbstractBidirList<G>, Queue<G>, Deque<G> {
private int _size = 0;
private int _stamp = 0;
private Node<G>? _head = null;
@@ -79,6 +79,13 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
/**
* { inheritDoc}
*/
+ public override BidirListIterator<G> bidir_list_iterator () {
+ return new Iterator<G> (this);
+ }
+
+ /**
+ * { inheritDoc}
+ */
public override int size {
get { return this._size; }
}
@@ -413,7 +420,7 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
}
}
- private class Iterator<G> : Object, Traversable<G>, Gee.Iterator<G>, BidirIterator<G>, ListIterator<G> {
+ private class Iterator<G> : Object, Traversable<G>, Gee.Iterator<G>, BidirIterator<G>, ListIterator<G>, BidirListIterator<G> {
private bool started = false;
private bool removed = false;
private unowned Node<G>? position;
diff --git a/gee/listiterator.vala b/gee/listiterator.vala
index 34eb3e0..2dfd0e9 100644
--- a/gee/listiterator.vala
+++ b/gee/listiterator.vala
@@ -23,19 +23,13 @@
/**
* A list iterator. This supports bi-directionnal and index-based iteration.
*/
-public interface Gee.ListIterator<G> : Gee.BidirIterator<G> {
+public interface Gee.ListIterator<G> : Gee.Iterator<G> {
/**
* Sets the current item in the iteration to the specified new item.
*/
public abstract void set (G item);
/**
- * Inserts the specified item before the current item in the iteration. The
- * cursor is let to point to the current item.
- */
- public abstract void insert (G item);
-
- /**
* Adds the specified item after the current item in the iteration. The
* cursor is moved to point to the new added item.
*/
diff --git a/gee/readonlybidirlist.vala b/gee/readonlybidirlist.vala
new file mode 100644
index 0000000..f516171
--- /dev/null
+++ b/gee/readonlybidirlist.vala
@@ -0,0 +1,73 @@
+/* readonlybidirlist.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+
+internal class Gee.ReadOnlyBidirList<G> : Gee.ReadOnlyList<G>, BidirList<G> {
+
+ /**
+ * Constructs a read-only list that mirrors the content of the specified
+ * list.
+ *
+ * @param list the list to decorate.
+ */
+ public ReadOnlyBidirList (BidirList<G> list) {
+ base (list);
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public BidirListIterator<G> bidir_list_iterator () {
+ return new Iterator<G> (((Gee.BidirList<G>) _collection).bidir_list_iterator ());
+ }
+
+ /**
+ * The read-only view of this list.
+ */
+ public virtual new BidirList<G> read_only_view { owned get { return this; } }
+
+ private class Iterator<G> : ReadOnlyList.Iterator<G>, BidirIterator<G>, BidirListIterator<G> {
+ public Iterator (ListIterator<G> iterator) {
+ base (iterator);
+ }
+
+ public bool previous () {
+ return ((BidirIterator<G>) _iter).previous ();
+ }
+
+ public bool has_previous () {
+ return ((BidirIterator<G>) _iter).has_previous ();
+ }
+
+ public bool first () {
+ return ((BidirIterator<G>) _iter).first ();
+ }
+
+ public bool last () {
+ return ((BidirIterator<G>) _iter).last ();
+ }
+
+ public void insert (G item) {
+ assert_not_reached ();
+ }
+ }
+}
+
diff --git a/gee/readonlylist.vala b/gee/readonlylist.vala
index 811f729..b0745e6 100644
--- a/gee/readonlylist.vala
+++ b/gee/readonlylist.vala
@@ -128,35 +128,15 @@ internal class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
}
- private class Iterator<G> : ReadOnlyCollection.Iterator<G>, BidirIterator<G>, ListIterator<G> {
+ protected class Iterator<G> : ReadOnlyCollection.Iterator<G>, ListIterator<G> {
public Iterator (ListIterator<G> iterator) {
base (iterator);
}
- public bool previous () {
- return ((ListIterator<G>) _iter).previous ();
- }
-
- public bool has_previous () {
- return ((ListIterator<G>) _iter).has_previous ();
- }
-
- public bool first () {
- return ((ListIterator<G>) _iter).first ();
- }
-
- public bool last () {
- return ((ListIterator<G>) _iter).last ();
- }
-
public new void set (G item) {
assert_not_reached ();
}
- public void insert (G item) {
- assert_not_reached ();
- }
-
public void add (G item) {
assert_not_reached ();
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dc3e202..5cc570c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ TEST_PROGS += tests
tests_SOURCES = \
testarraylist.vala \
+ testbidirlist.vala \
testcase.vala \
testcollection.vala \
testdeque.vala \
@@ -23,6 +24,7 @@ tests_SOURCES = \
testmultiset.vala \
testpriorityqueue.vala \
testqueue.vala \
+ testreadonlybidirlist.vala \
testreadonlycollection.vala \
testreadonlylist.vala \
testreadonlymap.vala \
diff --git a/tests/testarraylist.vala b/tests/testarraylist.vala
index 8964514..b13ec30 100644
--- a/tests/testarraylist.vala
+++ b/tests/testarraylist.vala
@@ -25,7 +25,7 @@
using Gee;
-public class ArrayListTests : ListTests {
+public class ArrayListTests : BidirListTests {
public ArrayListTests () {
base ("ArrayList");
diff --git a/tests/testbidirlist.vala b/tests/testbidirlist.vala
new file mode 100644
index 0000000..7e53f5b
--- /dev/null
+++ b/tests/testbidirlist.vala
@@ -0,0 +1,107 @@
+/* testbidirlist.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+
+using GLib;
+using Gee;
+
+public abstract class BidirListTests : ListTests {
+
+ public BidirListTests (string name) {
+ base (name);
+ add_test ("[List] bi-directional list iterator", test_bidir_list_iterator);
+ }
+
+ public void test_bidir_list_iterator () {
+ var test_list = test_collection as Gee.BidirList<string>;
+
+ // Check the test list is not null
+ assert (test_list != null);
+
+ // Check iterate empty list
+ var iterator = test_list.bidir_list_iterator ();
+ assert (! iterator.has_next ());
+ assert (! iterator.next ());
+ assert (! iterator.has_previous ());
+ assert (! iterator.previous ());
+ assert (! iterator.first ());
+ assert (! iterator.last ());
+
+ // Check iterate list
+ assert (test_list.add ("one"));
+ assert (test_list.add ("two"));
+ assert (test_list.add ("three"));
+
+ iterator = test_list.bidir_list_iterator ();
+ assert (iterator.next());
+ assert (iterator.get () == "one");
+ assert (iterator.index () == 0);
+ ((ListIterator<string>)iterator).set ("new one");
+ assert (iterator.next());
+ assert (iterator.get () == "two");
+ assert (iterator.index () == 1);
+ ((ListIterator<string>)iterator).set ("new two");
+ assert (test_list.size == 3);
+ assert (iterator.index () == 1);
+ iterator.insert ("before two");
+ assert (test_list.size == 4);
+ assert (iterator.index () == 2);
+ iterator.add ("after two");
+ assert (test_list.size == 5);
+ assert (iterator.index () == 3);
+ assert (iterator.next());
+ assert (iterator.get () == "three");
+ assert (iterator.index () == 4);
+ ((ListIterator<string>)iterator).set ("new three");
+ assert (! iterator.has_next ());
+ assert (! iterator.next ());
+
+ assert (iterator.first ());
+ assert (iterator.get () == "new one");
+ assert (iterator.index () == 0);
+ assert (! iterator.has_previous ());
+ assert (! iterator.previous ());
+
+ assert (iterator.last ());
+ assert (iterator.get () == "new three");
+ assert (iterator.index () == 4);
+ assert (! iterator.has_next ());
+ assert (! iterator.next ());
+
+ assert (iterator.has_previous ());
+ assert (iterator.previous ());
+ assert (iterator.get () == "after two");
+ assert (iterator.index () == 3);
+ assert (iterator.has_previous ());
+ assert (iterator.previous ());
+ assert (iterator.get () == "new two");
+ assert (iterator.index () == 2);
+ assert (iterator.has_previous ());
+ assert (iterator.previous ());
+ assert (iterator.get () == "before two");
+ assert (iterator.index () == 1);
+ assert (iterator.has_previous ());
+ assert (iterator.previous ());
+ assert (iterator.get () == "new one");
+ assert (iterator.index () == 0);
+ }
+}
+
diff --git a/tests/testlinkedlist.vala b/tests/testlinkedlist.vala
index b86b734..bff2c5c 100644
--- a/tests/testlinkedlist.vala
+++ b/tests/testlinkedlist.vala
@@ -24,7 +24,7 @@
using Gee;
-public class LinkedListTests : ListTests {
+public class LinkedListTests : BidirListTests {
public LinkedListTests () {
base ("LinkedList");
diff --git a/tests/testlist.vala b/tests/testlist.vala
index 48ca387..5b83b49 100644
--- a/tests/testlist.vala
+++ b/tests/testlist.vala
@@ -83,10 +83,6 @@ public abstract class ListTests : CollectionTests {
var iterator = test_list.list_iterator ();
assert (! iterator.has_next ());
assert (! iterator.next ());
- assert (! iterator.has_previous ());
- assert (! iterator.previous ());
- assert (! iterator.first ());
- assert (! iterator.last ());
// Check iterate list
assert (test_list.add ("one"));
@@ -104,45 +100,18 @@ public abstract class ListTests : CollectionTests {
iterator.set ("new two");
assert (test_list.size == 3);
assert (iterator.index () == 1);
- iterator.insert ("before two");
+ iterator.add ("after two");
assert (test_list.size == 4);
assert (iterator.index () == 2);
- iterator.add ("after two");
- assert (test_list.size == 5);
- assert (iterator.index () == 3);
assert (iterator.next());
assert (iterator.get () == "three");
- assert (iterator.index () == 4);
+ assert (iterator.index () == 3);
iterator.set ("new three");
assert (! iterator.has_next ());
assert (! iterator.next ());
- assert (iterator.first ());
- assert (iterator.get () == "new one");
- assert (iterator.index () == 0);
- assert (! iterator.has_previous ());
- assert (! iterator.previous ());
-
- assert (iterator.last ());
- assert (iterator.get () == "new three");
- assert (iterator.index () == 4);
- assert (! iterator.has_next ());
- assert (! iterator.next ());
-
- assert (iterator.has_previous ());
- assert (iterator.previous ());
- assert (iterator.get () == "after two");
- assert (iterator.index () == 3);
- assert (iterator.has_previous ());
- assert (iterator.previous ());
- assert (iterator.get () == "new two");
- assert (iterator.index () == 2);
- assert (iterator.has_previous ());
- assert (iterator.previous ());
- assert (iterator.get () == "before two");
- assert (iterator.index () == 1);
- assert (iterator.has_previous ());
- assert (iterator.previous ());
+ iterator = test_list.list_iterator ();
+ assert (iterator.next ());
assert (iterator.get () == "new one");
assert (iterator.index () == 0);
}
diff --git a/tests/testmain.vala b/tests/testmain.vala
index bf47806..214a241 100644
--- a/tests/testmain.vala
+++ b/tests/testmain.vala
@@ -33,6 +33,7 @@ void main (string[] args) {
TestSuite.get_root ().add_suite (new LinkedListTests ().get_suite ());
TestSuite.get_root ().add_suite (new LinkedListAsDequeTests ().get_suite ());
TestSuite.get_root ().add_suite (new PriorityQueueTests ().get_suite ());
+ TestSuite.get_root ().add_suite (new ReadOnlyBidirListTests ().get_suite ());
TestSuite.get_root ().add_suite (new ReadOnlyCollectionTests ().get_suite ());
TestSuite.get_root ().add_suite (new ReadOnlyListTests ().get_suite ());
TestSuite.get_root ().add_suite (new ReadOnlyMapTests ().get_suite ());
diff --git a/tests/testreadonlybidirlist.vala b/tests/testreadonlybidirlist.vala
new file mode 100644
index 0000000..409e744
--- /dev/null
+++ b/tests/testreadonlybidirlist.vala
@@ -0,0 +1,119 @@
+/* testreadonlybidirlist.vala
+ *
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2 gmail com>
+ */
+
+using Gee;
+
+public class ReadOnlyBidirListTests : ReadOnlyListTests {
+
+ public ReadOnlyBidirListTests () {
+ base.with_name ("ReadOnlyBidirList");
+ add_test ("[ReadOnlyBidirList] immutable iterator", test_immutable_iterator);
+ }
+
+ protected override Collection<string> get_ro_view (Collection<string> collection) {
+ return ((Gee.BidirList) collection).read_only_view;
+ }
+
+ public new void test_immutable_iterator () {
+ var test_list = test_collection as Gee.BidirList<string>;
+ var ro_list = ro_collection as Gee.BidirList<string>;
+
+ assert (test_list.add ("one"));
+ assert (test_list.add ("two"));
+
+ assert (ro_list.size == 2);
+ assert (ro_list.get (0) == "one");
+ assert (ro_list.get (1) == "two");
+
+ Gee.BidirListIterator<string> iterator = ro_list.bidir_list_iterator ();
+
+ assert (iterator.has_next ());
+ assert (iterator.next ());
+ assert (iterator.get () == "one");
+ assert (iterator.index () == 0);
+
+ assert (iterator.has_next ());
+ assert (iterator.next ());
+ assert (iterator.get () == "two");
+ assert (iterator.index () == 1);
+
+ assert (! iterator.has_next ());
+ assert (! iterator.next ());
+
+ assert (iterator.has_previous ());
+ assert (iterator.previous ());
+ assert (iterator.get () == "one");
+ assert (iterator.index () == 0);
+
+ assert (iterator.last ());
+ assert (iterator.get () == "two");
+ assert (iterator.index () == 1);
+
+ assert (iterator.first ());
+ assert (iterator.get () == "one");
+ assert (iterator.index () == 0);
+
+ if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+ TestTrapFlags.SILENCE_STDERR)) {
+ iterator.remove ();
+ Posix.exit (0);
+ }
+ Test.trap_assert_failed ();
+ assert (ro_list.size == 2);
+ assert (ro_list.get (0) == "one");
+ assert (ro_list.get (1) == "two");
+ assert (iterator.index () == 0);
+
+ if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+ TestTrapFlags.SILENCE_STDERR)) {
+ iterator.set ("three");
+ Posix.exit (0);
+ }
+ Test.trap_assert_failed ();
+ assert (ro_list.size == 2);
+ assert (ro_list.get (0) == "one");
+ assert (ro_list.get (1) == "two");
+ assert (iterator.index () == 0);
+
+ if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+ TestTrapFlags.SILENCE_STDERR)) {
+ iterator.insert ("three");
+ Posix.exit (0);
+ }
+ Test.trap_assert_failed ();
+ assert (ro_list.size == 2);
+ assert (ro_list.get (0) == "one");
+ assert (ro_list.get (1) == "two");
+ assert (iterator.index () == 0);
+
+ if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+ TestTrapFlags.SILENCE_STDERR)) {
+ iterator.add ("three");
+ Posix.exit (0);
+ }
+ Test.trap_assert_failed ();
+ assert (ro_list.size == 2);
+ assert (ro_list.get (0) == "one");
+ assert (ro_list.get (1) == "two");
+ assert (iterator.index () == 0);
+ }
+}
diff --git a/tests/testreadonlylist.vala b/tests/testreadonlylist.vala
index d1b2220..9db5e40 100644
--- a/tests/testreadonlylist.vala
+++ b/tests/testreadonlylist.vala
@@ -28,7 +28,11 @@ using Gee;
public class ReadOnlyListTests : ReadOnlyCollectionTests {
public ReadOnlyListTests () {
- base.with_name ("ReadOnlyList");
+ this.with_name ("ReadOnlyList");
+ }
+
+ public ReadOnlyListTests.with_name (string name) {
+ base.with_name (name);
add_test ("[ReadOnlyList] immutable iterator", test_immutable_iterator);
add_test ("[ReadOnlyList] immutable", test_immutable);
add_test ("[ReadOnlyList] accurate view", test_accurate_view);
@@ -74,18 +78,8 @@ public class ReadOnlyListTests : ReadOnlyCollectionTests {
assert (! iterator.has_next ());
assert (! iterator.next ());
- assert (iterator.has_previous ());
- assert (iterator.previous ());
- assert (iterator.get () == "one");
- assert (iterator.index () == 0);
-
- assert (iterator.last ());
- assert (iterator.get () == "two");
- assert (iterator.index () == 1);
-
- assert (iterator.first ());
- assert (iterator.get () == "one");
- assert (iterator.index () == 0);
+ iterator = ro_list.list_iterator ();
+ assert (iterator.next ());
if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
TestTrapFlags.SILENCE_STDERR)) {
@@ -109,12 +103,6 @@ public class ReadOnlyListTests : ReadOnlyCollectionTests {
assert (ro_list.get (1) == "two");
assert (iterator.index () == 0);
- if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
- TestTrapFlags.SILENCE_STDERR)) {
- iterator.insert ("three");
- Posix.exit (0);
- }
- Test.trap_assert_failed ();
assert (ro_list.size == 2);
assert (ro_list.get (0) == "one");
assert (ro_list.get (1) == "two");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]