summaryrefslogtreecommitdiffstats
path: root/src/tests/eina_graph_suite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/eina_graph_suite.c')
-rw-r--r--src/tests/eina_graph_suite.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c
index c49653d..dea46e9 100644
--- a/src/tests/eina_graph_suite.c
+++ b/src/tests/eina_graph_suite.c
@@ -23,6 +23,61 @@ _feed_simple_graph(Eina_Graph *g)
ck_assert(eina_graph_edge_add(g, 5, 3) == EINA_TRUE);
}
+START_TEST (test_eina_graph_simple_dfs)
+{
+ Eina_Graph_DFS *dfs;
+ Eina_List *path, *l;
+ void *data;
+ int i;
+ unsigned int vsr[] = { 0, 5, 4, 3 };
+ unsigned int vss[] = { 0, 6, 4, 5, 3 };
+
+ ck_assert(eina_graph_init() == 1);
+ Eina_Graph *g = eina_graph_new(13, 2);
+ ck_assert(g != NULL);
+
+ _feed_simple_graph(g);
+
+ dfs = eina_graph_dfs_new(g, 0, EINA_TRUE);
+ ck_assert(eina_graph_dfs_source(dfs) == 0);
+ ck_assert(eina_graph_dfs_has_path_to(dfs, 12) == EINA_FALSE);
+ ck_assert(eina_graph_dfs_path_to(dfs, 12) == NULL);
+ ck_assert(eina_graph_dfs_path_to(dfs, 15) == NULL);
+ ck_assert(eina_graph_dfs_has_path_to(dfs, 3) == EINA_TRUE);
+ path = eina_graph_dfs_path_to(dfs, 3);
+ ck_assert(path != NULL);
+ ck_assert(eina_list_count(path) == (sizeof(vsr)/sizeof(*vsr)));
+ i = 0;
+ EINA_LIST_FOREACH(path, l, data)
+ {
+ ck_assert(vsr[i] == (unsigned int) data);
+ i++;
+ }
+ eina_graph_dfs_free(dfs);
+
+ dfs = eina_graph_dfs_new(g, 0, EINA_FALSE);
+ ck_assert(eina_graph_dfs_source(dfs) == 0);
+ ck_assert(eina_graph_dfs_has_path_to(dfs, 12) == EINA_FALSE);
+ ck_assert(eina_graph_dfs_path_to(dfs, 12) == NULL);
+ ck_assert(eina_graph_dfs_path_to(dfs, 15) == NULL);
+ ck_assert(eina_graph_dfs_has_path_to(dfs, 3) == EINA_TRUE);
+ path = eina_graph_dfs_path_to(dfs, 3);
+ ck_assert(path != NULL);
+ ck_assert(eina_list_count(path) == (sizeof(vss)/sizeof(*vss)));
+ i = 0;
+ EINA_LIST_FOREACH(path, l, data)
+ {
+ ck_assert(vss[i] == (unsigned int) data);
+ i++;
+ }
+ eina_graph_dfs_free(dfs);
+
+ eina_graph_free(g);
+
+ ck_assert(eina_graph_shutdown() == 0);
+}
+END_TEST
+
START_TEST (test_eina_graph_simple)
{
ck_assert(eina_graph_init() == 1);
@@ -42,6 +97,7 @@ START_TEST (test_eina_graph_simple)
ck_assert(eina_graph_edges_count(g) == 13);
ck_assert(eina_graph_degree(g, 4) == 3);
ck_assert(eina_graph_degree(g, 0) == 4);
+ ck_assert(eina_graph_degree(g, 15) == 0);
ck_assert(eina_graph_degree_max(g) == 4);
ck_assert(eina_graph_degree_avg(g) == 2.0);
ck_assert(eina_graph_self_loops(g) == 0);
@@ -73,6 +129,10 @@ eina_graph_suite (void)
tcase_add_test (tc_simple, test_eina_graph_simple);
suite_add_tcase (s, tc_simple);
+ TCase *tc_simple_dfs = tcase_create ("Simple Graph DFS");
+ tcase_add_test (tc_simple_dfs, test_eina_graph_simple_dfs);
+ suite_add_tcase (s, tc_simple_dfs);
+
return s;
}