aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests/test_intset.vala
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests/test_intset.vala')
-rw-r--r--tests/unit_tests/test_intset.vala85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/unit_tests/test_intset.vala b/tests/unit_tests/test_intset.vala
index 246a584d..2bc54a3c 100644
--- a/tests/unit_tests/test_intset.vala
+++ b/tests/unit_tests/test_intset.vala
@@ -35,6 +35,14 @@ void test_intset_new () {
assert (intset.dump() == "");
}
+void test_intset_sized_new () {
+ IntSet intset = new IntSet.sized(0);
+ assert (intset.dump() == "");
+ IntSet intset2 = new IntSet.sized(10);
+ assert (intset2.dump() == "");
+}
+
+
void test_intset_add () {
IntSet intset = new IntSet();
intset.add (TestValues.A);
@@ -49,6 +57,37 @@ void test_intset_add () {
assert (intset.is_member (TestValues.E));
}
+void test_intset_remove() {
+ IntSet intset = new IntSet();
+ intset.add (TestValues.A);
+ intset.add (TestValues.B);
+ intset.add (TestValues.C);
+ intset.add (TestValues.D);
+ intset.add (TestValues.E);
+ assert (intset.remove (TestValues.B) == true);
+ assert (intset.is_member (TestValues.A));
+ assert (!intset.is_member (TestValues.B));
+ assert (intset.is_member (TestValues.C));
+ assert (intset.is_member (TestValues.D));
+ assert (intset.is_member (TestValues.E));
+
+ //check error cases
+ assert (intset.remove (1234) == false);
+ assert (intset.remove (1234567) == false);
+
+ //remove everything
+ assert (intset.remove (TestValues.A) == true);
+ assert (intset.remove (TestValues.C) == true);
+ assert (intset.remove (TestValues.D) == true);
+ assert (intset.remove (TestValues.E) == true);
+
+ assert(intset.size() == 0);
+
+ //remove something already removed
+ assert(intset.remove (TestValues.A) == false);
+}
+
+
void test_intset_intersect () {
IntSet i1 = new IntSet();
IntSet i2 = new IntSet();
@@ -84,14 +123,60 @@ void test_intset_disjoint () {
assert (i1.is_disjoint (i2));
}
+void test_intset_is_subset_of() {
+ IntSet i1 = new IntSet();
+ IntSet i2 = new IntSet();
+ i1.add (TestValues.A);
+ i1.add (TestValues.B);
+ i1.add (TestValues.C);
+ i2.add (TestValues.B);
+ i2.add (TestValues.C);
+
+ assert (!i1.is_subset_of(i2));
+ assert (i2.is_subset_of(i1));
+
+ i2.add (TestValues.D);
+
+ assert (!i2.is_subset_of(i1));
+}
+
+void test_intset_is_equal() {
+ IntSet i1 = new IntSet();
+ IntSet i2 = new IntSet();
+ i1.add (TestValues.A);
+ i1.add (TestValues.B);
+ i1.add (TestValues.C);
+ i2.add (TestValues.B);
+ i2.add (TestValues.C);
+ assert (!i1.is_subset_of(i2));
+ assert (i2.is_subset_of(i1));
+
+ i2.add (TestValues.D);
+
+ assert (!i2.is_subset_of(i1));
+}
+
+void test_intset_dump() {
+ IntSet intset = new IntSet();
+ intset.add (TestValues.A);
+ intset.add (TestValues.B);
+ intset.add (TestValues.C);
+ intset.add (TestValues.D);
+ intset.add (TestValues.E);
+ assert (intset.dump() == "1 2 3 10000 10001");
+}
public static void main (string[] args) {
Test.init (ref args);
Test.add_func("/contextkit/intset/new", test_intset_new);
+ Test.add_func("/contextkit/intset/sized_new", test_intset_sized_new);
Test.add_func("/contextkit/intset/add", test_intset_add);
+ Test.add_func("/contextkit/intset/remove", test_intset_remove);
Test.add_func("/contextkit/intset/intersect", test_intset_intersect);
Test.add_func("/contextkit/intset/disjoint", test_intset_disjoint);
+ Test.add_func("/contextkit/intset/is_subset_of", test_intset_is_subset_of);
+ Test.add_func("/contextkit/intset/dump", test_intset_dump);
Test.run ();
}