diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-03 23:17:02 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-03 23:17:02 +0100 |
commit | 77f3f35cefd06ea27a403830d129a523fa1aa3cb (patch) | |
tree | 8c35d130637bb32109e86cdbba74d0b453fb4a88 | |
parent | fb3483672193c2fc360d3c6e450dc051541556e5 (diff) | |
download | eina_graph-77f3f35cefd06ea27a403830d129a523fa1aa3cb.zip eina_graph-77f3f35cefd06ea27a403830d129a523fa1aa3cb.tar.gz |
refactor tests
-rw-r--r-- | src/tests/eina_graph_suite.c | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c index bb4cdf1..c866b36 100644 --- a/src/tests/eina_graph_suite.c +++ b/src/tests/eina_graph_suite.c @@ -7,7 +7,7 @@ #include "Eina_Graph.h" static void -_feed_simple_graph(Eina_Graph *g) +_feed_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); @@ -24,19 +24,19 @@ _feed_simple_graph(Eina_Graph *g) ck_assert(eina_graph_edge_add(g, 5, 3) == EINA_TRUE); } -START_TEST (test_eina_graph_simple_bfs) +static void _bfs_tests(unsigned int vertices[], unsigned int n) { + Eina_Graph *g; Eina_Graph_BFS *bfs; Eina_List *path, *l; void *data; int i; - unsigned int vsr[] = { 0, 5, 3 }; ck_assert(eina_graph_init() == 1); - Eina_Graph *g = eina_graph_new(13, 2); + g = eina_graph_new(13, 2); ck_assert(g != NULL); - _feed_simple_graph(g); + _feed_graph(g); bfs = eina_graph_bfs_new(g, 0); ck_assert(eina_graph_bfs_source(bfs) == 0); @@ -48,11 +48,11 @@ START_TEST (test_eina_graph_simple_bfs) ck_assert(eina_graph_bfs_dist_to(bfs, 3) == 2); path = eina_graph_bfs_path_to(bfs, 3); ck_assert(path != NULL); - ck_assert(eina_list_count(path) == (sizeof(vsr)/sizeof(*vsr))); + ck_assert(eina_list_count(path) == n); i = 0; EINA_LIST_FOREACH(path, l, data) { - ck_assert(vsr[i] == CAST_D(data)); + ck_assert(vertices[i] == CAST_D(data)); i++; } eina_graph_bfs_free(bfs); @@ -61,41 +61,29 @@ START_TEST (test_eina_graph_simple_bfs) ck_assert(eina_graph_shutdown() == 0); } + +START_TEST (test_eina_graph_bfs) +{ + unsigned int vertices[] = { 0, 5, 3 }; + _bfs_tests(vertices, (sizeof(vertices)/sizeof(*vertices))); +} END_TEST -START_TEST (test_eina_graph_simple_dfs) +static void _dfs_tests(Eina_Bool r, unsigned int vertices[], unsigned int n) { + Eina_Graph *g; 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); + 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] == CAST_D(data)); - i++; - } - eina_graph_dfs_free(dfs); + _feed_graph(g); - dfs = eina_graph_dfs_new(g, 0, EINA_FALSE); + dfs = eina_graph_dfs_new(g, 0, r); 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); @@ -103,11 +91,11 @@ START_TEST (test_eina_graph_simple_dfs) 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))); + ck_assert(eina_list_count(path) == n); i = 0; EINA_LIST_FOREACH(path, l, data) { - ck_assert(vss[i] == CAST_D(data)); + ck_assert(vertices[i] == CAST_D(data)); i++; } eina_graph_dfs_free(dfs); @@ -116,19 +104,28 @@ START_TEST (test_eina_graph_simple_dfs) ck_assert(eina_graph_shutdown() == 0); } + +START_TEST (test_eina_graph_dfs) +{ + unsigned int v0[] = { 0, 5, 4, 3 }; + unsigned int v1[] = { 0, 6, 4, 5, 3 }; + _dfs_tests(EINA_TRUE, v0, (sizeof(v0)/sizeof(*v0))); + _dfs_tests(EINA_FALSE, v1, (sizeof(v1)/sizeof(*v1))); +} END_TEST -START_TEST (test_eina_graph_simple) +START_TEST (test_eina_graph) { FILE *outf; + Eina_Graph *g; ck_assert(eina_graph_init() == 1); ck_assert(eina_graph_init() == 2); - Eina_Graph *g = eina_graph_new(13, 2); + g = eina_graph_new(13, 2); ck_assert(g != NULL); - _feed_simple_graph(g); + _feed_graph(g); ck_assert(eina_graph_edge_add(g, -1, 3) == EINA_FALSE); ck_assert(eina_graph_edge_add(g, 3, -1) == EINA_FALSE); @@ -155,7 +152,7 @@ START_TEST (test_eina_graph_simple) ck_assert(eina_graph_degree_avg(g) < 2.154); ck_assert(eina_graph_self_loops(g) == 1); - outf = fopen("/tmp/eina_graph.dot", "w"); + outf = fopen("./eina_graph.dot", "w"); eina_graph_dot_write(g, outf); fclose(outf); @@ -169,19 +166,20 @@ END_TEST Suite * eina_graph_suite (void) { + TCase *tc; Suite *s = suite_create ("Eina Graph"); - TCase *tc_simple = tcase_create ("Simple Graph"); - tcase_add_test (tc_simple, test_eina_graph_simple); - suite_add_tcase (s, tc_simple); + tc = tcase_create ("Graph"); + tcase_add_test (tc, test_eina_graph); + suite_add_tcase (s, tc); - 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); + tc = tcase_create ("Graph DFS"); + tcase_add_test (tc, test_eina_graph_dfs); + suite_add_tcase (s, tc); - TCase *tc_simple_bfs = tcase_create ("Simple Graph BFS"); - tcase_add_test (tc_simple_bfs, test_eina_graph_simple_bfs); - suite_add_tcase (s, tc_simple_bfs); + tc = tcase_create ("Graph BFS"); + tcase_add_test (tc, test_eina_graph_bfs); + suite_add_tcase (s, tc); return s; } |