|
@@ -140,6 +140,109 @@ _graph_get (LSUP_StoreType type)
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int
|
|
|
+_graph_bool_ops (LSUP_StoreType type)
|
|
|
+{
|
|
|
+ const LSUP_StoreInt *sif = LSUP_store_int (type);
|
|
|
+ // Skip if the store doesn't support contexts.
|
|
|
+ if (!(sif->features & LSUP_STORE_CTX)) return 0;
|
|
|
+
|
|
|
+ if (sif->setup_fn) sif->setup_fn (NULL, true);
|
|
|
+
|
|
|
+ LSUP_Triple **trp = create_triples();
|
|
|
+
|
|
|
+ LSUP_Store *store = LSUP_store_new (type, NULL, 0);
|
|
|
+ LSUP_Graph
|
|
|
+ *gr1 = LSUP_graph_new (store, NULL, NULL),
|
|
|
+ *gr2 = LSUP_graph_new (store, NULL, NULL),
|
|
|
+ *gr_dest;
|
|
|
+
|
|
|
+ // Add 2 groups of triples to different graphs.
|
|
|
+ void *it;
|
|
|
+
|
|
|
+ it = LSUP_graph_add_init (gr1);
|
|
|
+ for (size_t i = 0; i < 4; i++) {
|
|
|
+ LSUP_graph_add_iter(it, trp[i]);
|
|
|
+ }
|
|
|
+ LSUP_graph_add_done (it);
|
|
|
+
|
|
|
+ // Skip duplicate triples, we already tested those.
|
|
|
+ // trp[3] is in both graphs.
|
|
|
+ it = LSUP_graph_add_init (gr2);
|
|
|
+ for (size_t i = 3; i < 8; i++) {
|
|
|
+ LSUP_graph_add_iter(it, trp[i]);
|
|
|
+ }
|
|
|
+ LSUP_graph_add_done (it);
|
|
|
+
|
|
|
+ // Test union.
|
|
|
+ gr_dest = LSUP_graph_new (store, NULL, NULL);
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (LSUP_BOOL_UNION, gr1, gr2, gr_dest));
|
|
|
+ for (size_t i = 0; i < 8; i++)
|
|
|
+ ASSERT (LSUP_graph_contains (gr_dest, trp[i]), "Union test failed!");
|
|
|
+ LSUP_graph_free (gr_dest);
|
|
|
+
|
|
|
+ // Test subtraction.
|
|
|
+ gr_dest = LSUP_graph_new (store, NULL, NULL);
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (
|
|
|
+ LSUP_BOOL_SUBTRACTION, gr1, gr2, gr_dest));
|
|
|
+ for (size_t i = 0; i < 3; i++)
|
|
|
+ ASSERT (LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Subtraction test is missing triples!");
|
|
|
+ for (size_t i = 3; i < 8; i++)
|
|
|
+ ASSERT (!LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Subtraction test has excess triples!");
|
|
|
+ LSUP_graph_free (gr_dest);
|
|
|
+
|
|
|
+ gr_dest = LSUP_graph_new (store, NULL, NULL);
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (
|
|
|
+ LSUP_BOOL_SUBTRACTION, gr2, gr1, gr_dest));
|
|
|
+ for (size_t i = 0; i < 4; i++)
|
|
|
+ ASSERT (!LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Subtraction test is missing triples!");
|
|
|
+ for (size_t i = 4; i < 8; i++)
|
|
|
+ ASSERT (LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Subtraction test has excess triples!");
|
|
|
+ LSUP_graph_free (gr_dest);
|
|
|
+
|
|
|
+ // Test intersection.
|
|
|
+ gr_dest = LSUP_graph_new (store, NULL, NULL);
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (
|
|
|
+ LSUP_BOOL_INTERSECTION, gr1, gr2, gr_dest));
|
|
|
+ for (size_t i = 0; i < 3; i++)
|
|
|
+ ASSERT (!LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Intersection is missing triples!");
|
|
|
+ ASSERT (LSUP_graph_contains (
|
|
|
+ gr_dest, trp[3]), "Intersection test failed!");
|
|
|
+ for (size_t i = 4; i < 8; i++)
|
|
|
+ ASSERT (!LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "Intersection test has excess triples!");
|
|
|
+ LSUP_graph_free (gr_dest);
|
|
|
+
|
|
|
+ // Test XOR.
|
|
|
+ gr_dest = LSUP_graph_new (store, NULL, NULL);
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (LSUP_BOOL_XOR, gr1, gr2, gr_dest));
|
|
|
+ for (size_t i = 0; i < 3; i++)
|
|
|
+ ASSERT (LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "XOR test is missing triples!");
|
|
|
+ ASSERT (!LSUP_graph_contains (
|
|
|
+ gr_dest, trp[3]), "XOR test has excess triples!");
|
|
|
+ for (size_t i = 4; i < 8; i++)
|
|
|
+ ASSERT (LSUP_graph_contains (
|
|
|
+ gr_dest, trp[i]), "XOR test is missing triples!");
|
|
|
+ LSUP_graph_free (gr_dest);
|
|
|
+
|
|
|
+ // Test union with result graph as one of the sources.
|
|
|
+ EXPECT_PASS (LSUP_graph_bool_op (LSUP_BOOL_UNION, gr1, gr2, gr1));
|
|
|
+
|
|
|
+ LSUP_graph_free (gr1);
|
|
|
+ LSUP_graph_free (gr2);
|
|
|
+ free_triples (trp);
|
|
|
+ if (type != LSUP_STORE_HTABLE) LSUP_store_free (store);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int
|
|
|
_graph_lookup (LSUP_StoreType type)
|
|
|
{
|
|
@@ -398,6 +501,16 @@ BACKEND_TBL
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int test_graph_bool_ops() {
|
|
|
+#define ENTRY(a, b) \
|
|
|
+ if (_graph_bool_ops (LSUP_STORE_##a) != 0) return -1;
|
|
|
+BACKEND_TBL
|
|
|
+#undef ENTRY
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int test_graph_lookup() {
|
|
|
#define ENTRY(a, b) \
|
|
|
if (_graph_lookup (LSUP_STORE_##a) != 0) return -1;
|
|
@@ -480,6 +593,7 @@ int graph_tests()
|
|
|
RUN (test_graph_new);
|
|
|
RUN (test_graph_add);
|
|
|
RUN (test_graph_get);
|
|
|
+ RUN (test_graph_bool_ops);
|
|
|
RUN (test_graph_lookup);
|
|
|
RUN (test_graph_remove);
|
|
|
RUN (test_graph_copy);
|