[libgee] Add tests for Traversable methods implemented by Collections
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Add tests for Traversable methods implemented by Collections
- Date: Mon, 24 Sep 2012 10:37:12 +0000 (UTC)
commit adcc24ac95343098479d24f15dd8a29ee07e749b
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Mon Sep 24 12:36:58 2012 +0200
Add tests for Traversable methods implemented by Collections
tests/testcollection.vala | 117 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 114 insertions(+), 3 deletions(-)
---
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index 8b28f85..2c0050a 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -752,6 +752,9 @@ public abstract class CollectionTests : Gee.TestCase {
int count;
+ count = test_collection.fold<int> ((x, y) => {return y + 1;}, 0);
+ assert (count == 3);
+
count = test_collection.iterator ().fold<int> ((x, y) => {return y + 1;}, 0);
assert (count == 3);
@@ -768,13 +771,16 @@ public abstract class CollectionTests : Gee.TestCase {
int count = 0;
- test_collection.iterator ().foreach ((x) => {count++; return true;});
+ test_collection.foreach ((x) => {count++; return true;});
assert (count == 3);
+ test_collection.iterator ().foreach ((x) => {count++; return true;});
+ assert (count == 6);
+
Iterator<string> iter = test_collection.iterator ();
assert (iter.next ());
iter.foreach ((x) => {count++; return true;});
- assert (count == 6);
+ assert (count == 9);
}
public void test_map () {
@@ -816,6 +822,38 @@ public abstract class CollectionTests : Gee.TestCase {
assert (one);
assert (two);
assert (three);
+
+ one = two = three = false;
+ i = j = 0;
+
+ iter = test_collection.map<int> ((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 i++;
+ });
+ while (iter.next ()) {
+ assert (i == j);
+ assert (j == iter.get ());
+ assert (j == iter.get ());
+ j++;
+ assert (i == j);
+ }
+
+ assert (i == j);
+ assert (i == test_collection.size);
+ assert (one);
+ assert (two);
+ assert (three);
}
public void test_scan () {
@@ -854,6 +892,36 @@ public abstract class CollectionTests : Gee.TestCase {
assert (one);
assert (two);
assert (three);
+
+ one = two = three = false;
+ j = 0;
+
+ iter = test_collection.scan<int> ((str, cur) => {
+ 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 cur + 1;
+ }, 0);
+
+ do {
+ assert (j == iter.get ());
+ assert (j == iter.get ());
+ j++;
+ } while (iter.next ());
+
+ assert (j == test_collection.size + 1);
+ assert (one);
+ assert (two);
+ assert (three);
}
public void test_filter () {
@@ -884,8 +952,40 @@ public abstract class CollectionTests : Gee.TestCase {
assert (!iter.valid);
int j = 0;
- while (iter.next ())
+ while (iter.next ()) {
+ assert(iter.get () != "two");
+ j++;
+ }
+ assert (j == 2);
+ assert (one);
+ assert (two);
+ assert (three);
+
+ one = two = three = false;
+ j = 0;
+
+ iter = test_collection.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);
+
+ while (iter.next ()) {
+ assert(iter.get () != "two");
j++;
+ }
assert (j == 2);
assert (one);
assert (two);
@@ -907,6 +1007,17 @@ public abstract class CollectionTests : Gee.TestCase {
assert (iter2.get () == iter.get ());
assert (!iter.next ());
assert (iter2.next ());
+
+ iter = test_collection.chop (1, 1);
+ assert (!iter.valid);
+ iter2 = test_collection.iterator();
+
+ assert (iter2.next ());
+ assert (iter2.next ());
+ assert (iter.next ());
+ assert (iter2.get () == iter.get ());
+ assert (!iter.next ());
+ assert (iter2.next ());
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]