[libgee] Reintroduce tests
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Reintroduce tests
- Date: Sat, 21 Aug 2010 19:23:20 +0000 (UTC)
commit 556f314824e75ba2372c4b5e94773eeee8351744
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Sat Aug 21 20:37:41 2010 +0200
Reintroduce tests
tests/Makefile.am | 1 +
tests/testfunctions.vala | 126 ++++++++++++++++++++++++++++++++++++++++++++++
tests/testmain.vala | 1 +
3 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f517efb..4e63a0d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,6 +10,7 @@ tests_SOURCES = \
testcollection.vala \
testcomparable.vala \
testdeque.vala \
+ testfunctions.vala \
testhashmap.vala \
testhashmultimap.vala \
testhashmultiset.vala \
diff --git a/tests/testfunctions.vala b/tests/testfunctions.vala
new file mode 100644
index 0000000..57598ee
--- /dev/null
+++ b/tests/testfunctions.vala
@@ -0,0 +1,126 @@
+/* testfunctions.vala
+ *
+ * Copyright (C) 2010 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 class FunctionsTests : Gee.TestCase {
+ public FunctionsTests () {
+ base ("Functions");
+ add_test ("[Functions] comparing and hashing strings", test_string_func);
+ add_test ("[Functions] comparing and hashing int", test_int_func);
+ add_test ("[Functions] comparing and hashing instances of Comparable", test_compare_func);
+ }
+
+ public void test_string_func () {
+ string one = "one";
+ string two = "two";
+ string twoCopy = two.dup ();
+
+ Gee.EqualDataFunc eq = Gee.Functions.get_equal_func_for (typeof (string));
+ CompareDataFunc cmp = Gee.Functions.get_compare_func_for (typeof (string));
+ Gee.HashDataFunc hash = Gee.Functions.get_hash_func_for (typeof (string));
+ assert (eq != null);
+ assert (cmp != null);
+ assert (hash != null);
+
+ assert (eq (two, two));
+ assert (cmp (two, two) == 0);
+ assert (hash (two) == hash (two));
+
+ assert (eq (two, twoCopy));
+ assert (cmp (two, twoCopy) == 0);
+ assert (hash (two) == hash (twoCopy));
+
+ assert (!eq (one, two));
+ assert (cmp (one, two) < 0);
+
+ assert (!eq (two, one));
+ assert (cmp (two, one) >= 0);
+ }
+
+ public void test_int_func () {
+ void *one = (void *)1;
+ void *two = (void *)2;
+
+ Gee.EqualDataFunc eq = Gee.Functions.get_equal_func_for (typeof (int));
+ CompareDataFunc cmp = Gee.Functions.get_compare_func_for (typeof (int));
+ Gee.HashDataFunc hash = Gee.Functions.get_hash_func_for (typeof (int));
+
+ assert (eq != null);
+ assert (cmp != null);
+ assert (hash != null);
+
+ assert (eq (two, two));
+ assert (cmp (two, two) == 0);
+ assert (hash (two) == hash (two));
+
+ assert (!eq (one, two));
+ assert (cmp (one, two) < 0);
+
+ assert (!eq (two, one));
+ assert (cmp (two, one) >= 0);
+ }
+
+ public void test_compare_func () {
+ MyComparable two = new MyComparable(2);
+ MyComparable one = new MyComparable(1);
+ MyComparable twoCopy = new MyComparable(2);
+
+ Gee.EqualDataFunc eq = Gee.Functions.get_equal_func_for (typeof (MyComparable));
+ CompareDataFunc cmp = Gee.Functions.get_compare_func_for (typeof (MyComparable));
+ //Gee.HashDataFunc hash = Gee.Functions.get_hash_func_for (typeof (MyComparable));
+
+ assert (eq != null);
+ assert (cmp != null);
+ //assert (hash != null);
+
+ assert (eq (two, two));
+ assert (cmp (two, two) == 0);
+ //assert (hash (two) == hash (two));
+
+ assert (eq (two, twoCopy));
+ assert (cmp (two, twoCopy) == 0);
+ //assert (hash (two) == hash (twoCopy));
+
+ assert (!eq (one, two));
+ assert (cmp (one, two) < 0);
+
+ assert (!eq (two, one));
+ assert (cmp (two, one) >= 0);
+ }
+
+ private class MyComparable : GLib.Object, Gee.Comparable<MyComparable> {
+ public MyComparable(int i) {
+ this.i = i;
+ }
+
+ public int compare_to (MyComparable cmp) {
+ if (i == cmp.i)
+ return 0;
+ else if (i >= cmp.i)
+ return 1;
+ else
+ return -1;
+ }
+
+ int i;
+ }
+}
+
diff --git a/tests/testmain.vala b/tests/testmain.vala
index ad6e992..953c6ce 100644
--- a/tests/testmain.vala
+++ b/tests/testmain.vala
@@ -26,6 +26,7 @@ void main (string[] args) {
TestSuite.get_root ().add_suite (new ArrayListTests ().get_suite ());
TestSuite.get_root ().add_suite (new ComparableTests ().get_suite ());
+ TestSuite.get_root ().add_suite (new FunctionsTests ().get_suite ());
TestSuite.get_root ().add_suite (new HashMapTests ().get_suite ());
TestSuite.get_root ().add_suite (new HashMultiMapTests ().get_suite ());
TestSuite.get_root ().add_suite (new HashMultiSetTests ().get_suite ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]