summaryrefslogtreecommitdiffstats
path: root/src/tests/eina_graph_suite.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-01-10 16:46:46 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-01-10 16:46:46 +0100
commitef6d10c4980eaf0feeb8569bc983075cc023ad83 (patch)
tree4f82e80470706ecd53aa5ef0824479e357d6f0d7 /src/tests/eina_graph_suite.c
parentfb3483672193c2fc360d3c6e450dc051541556e5 (diff)
downloadeina_graph-ef6d10c4980eaf0feeb8569bc983075cc023ad83.zip
eina_graph-ef6d10c4980eaf0feeb8569bc983075cc023ad83.tar.gz
add eina_graph supports directed graphs
Diffstat (limited to 'src/tests/eina_graph_suite.c')
-rw-r--r--src/tests/eina_graph_suite.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c
index bb4cdf1..14b21f8 100644
--- a/src/tests/eina_graph_suite.c
+++ b/src/tests/eina_graph_suite.c
@@ -33,7 +33,7 @@ START_TEST (test_eina_graph_simple_bfs)
unsigned int vsr[] = { 0, 5, 3 };
ck_assert(eina_graph_init() == 1);
- Eina_Graph *g = eina_graph_new(13, 2);
+ Eina_Graph *g = eina_graph_new(13, 2, EINA_FALSE);
ck_assert(g != NULL);
_feed_simple_graph(g);
@@ -73,7 +73,7 @@ START_TEST (test_eina_graph_simple_dfs)
unsigned int vss[] = { 0, 6, 4, 5, 3 };
ck_assert(eina_graph_init() == 1);
- Eina_Graph *g = eina_graph_new(13, 2);
+ Eina_Graph *g = eina_graph_new(13, 2, EINA_FALSE);
ck_assert(g != NULL);
_feed_simple_graph(g);
@@ -125,11 +125,13 @@ START_TEST (test_eina_graph_simple)
ck_assert(eina_graph_init() == 1);
ck_assert(eina_graph_init() == 2);
- Eina_Graph *g = eina_graph_new(13, 2);
+ Eina_Graph *g = eina_graph_new(13, 2, EINA_FALSE);
ck_assert(g != NULL);
_feed_simple_graph(g);
+ ck_assert(eina_graph_directed(g) == EINA_FALSE);
+
ck_assert(eina_graph_edge_add(g, -1, 3) == EINA_FALSE);
ck_assert(eina_graph_edge_add(g, 3, -1) == EINA_FALSE);
ck_assert(eina_graph_edge_add(g, 13, 3) == EINA_FALSE);
@@ -161,6 +163,44 @@ START_TEST (test_eina_graph_simple)
eina_graph_free(g);
+ g = eina_graph_new(13, 2, EINA_TRUE);
+ ck_assert(g != NULL);
+
+ _feed_simple_graph(g);
+
+ ck_assert(eina_graph_directed(g) == EINA_TRUE);
+
+ ck_assert(eina_graph_edge_add(g, -1, 3) == EINA_FALSE);
+ ck_assert(eina_graph_edge_add(g, 3, -1) == EINA_FALSE);
+ ck_assert(eina_graph_edge_add(g, 13, 3) == EINA_FALSE);
+ ck_assert(eina_graph_edge_add(g, 3, 13) == EINA_FALSE);
+
+ ck_assert(eina_graph_vertices_count(g) == 13);
+ ck_assert(eina_graph_edges_count(g) == 13);
+ ck_assert(eina_graph_degree(g, 4) == 1);
+ 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);
+
+ ck_assert(eina_graph_edge_add(g, 0, 0) == EINA_TRUE);
+
+ ck_assert(eina_graph_vertices_count(g) == 13);
+ ck_assert(eina_graph_edges_count(g) == 14);
+ ck_assert(eina_graph_degree(g, 4) == 1);
+ ck_assert(eina_graph_degree(g, 0) == 5);
+ ck_assert(eina_graph_degree_max(g) == 5);
+ ck_assert(eina_graph_degree_avg(g) > 2.153);
+ ck_assert(eina_graph_degree_avg(g) < 2.154);
+ ck_assert(eina_graph_self_loops(g) == 1);
+
+ outf = fopen("/tmp/eina_graph_directed.dot", "w");
+ eina_graph_dot_write(g, outf);
+ fclose(outf);
+
+ eina_graph_free(g);
+
ck_assert(eina_graph_shutdown() == 1);
ck_assert(eina_graph_shutdown() == 0);
}