summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-12-25 20:25:46 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-12-25 20:25:46 +0100
commit78cc6d7c071fcc6ff1dc9458443168f4c0fa76ca (patch)
treef9e01c828f3ec348c17f927d1a96f5b83ae0dd6d
parentbd715870e1a688073d0a23b7f75bf2a6635f7a2b (diff)
downloadeina_graph-78cc6d7c071fcc6ff1dc9458443168f4c0fa76ca.zip
eina_graph-78cc6d7c071fcc6ff1dc9458443168f4c0fa76ca.tar.gz
add test case for basic Eina_Graph functions
-rw-r--r--src/tests/eina_graph_suite.c56
1 files changed, 52 insertions, 4 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c
index 79c02aa..c49653d 100644
--- a/src/tests/eina_graph_suite.c
+++ b/src/tests/eina_graph_suite.c
@@ -5,12 +5,60 @@
#include <check.h>
#include "Eina_Graph.h"
+static void
+_feed_simple_graph(Eina_Graph *g)
+{
+ ck_assert(eina_graph_edge_add(g, 0, 5) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 4, 3) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 0, 1) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 9, 12) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 6, 4) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 5, 4) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 0, 2) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 11, 12) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 9, 10) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 0, 6) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 7, 8) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 9, 11) == EINA_TRUE);
+ ck_assert(eina_graph_edge_add(g, 5, 3) == EINA_TRUE);
+}
-START_TEST (test_eina_graph_lib)
+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);
+ ck_assert(g != NULL);
+
+ _feed_simple_graph(g);
+
+ 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) == 3);
+ ck_assert(eina_graph_degree(g, 0) == 4);
+ 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) == 3);
+ 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);
+
+ eina_graph_free(g);
+
ck_assert(eina_graph_shutdown() == 1);
ck_assert(eina_graph_shutdown() == 0);
}
@@ -21,9 +69,9 @@ eina_graph_suite (void)
{
Suite *s = suite_create ("Eina Graph");
- TCase *tc_core = tcase_create ("Core");
- tcase_add_test (tc_core, test_eina_graph_lib);
- suite_add_tcase (s, tc_core);
+ TCase *tc_simple = tcase_create ("Simple Graph");
+ tcase_add_test (tc_simple, test_eina_graph_simple);
+ suite_add_tcase (s, tc_simple);
return s;
}