diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-22 10:40:19 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-22 10:40:19 +0100 | 
| commit | b456a79928e650dd31d7ed4e1de1bc7a492c79cd (patch) | |
| tree | 7e607e852654e945cd6d3f2f20580cb26ce8270a /src/tests | |
| parent | ef6d10c4980eaf0feeb8569bc983075cc023ad83 (diff) | |
| download | eina_graph-directed.zip eina_graph-directed.tar.gz  | |
refactor testsdirected
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/eina_graph_suite.c | 123 | 
1 files changed, 82 insertions, 41 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c index 14b21f8..becb066 100644 --- a/src/tests/eina_graph_suite.c +++ b/src/tests/eina_graph_suite.c @@ -24,16 +24,17 @@ _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(Eina_Bool directed, +                       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, EINA_FALSE); +   g = eina_graph_new(13, 2, directed);     ck_assert(g != NULL);     _feed_simple_graph(g); @@ -48,11 +49,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 +62,37 @@ START_TEST (test_eina_graph_simple_bfs)     ck_assert(eina_graph_shutdown() == 0);  } + +START_TEST (test_eina_graph_simple_bfs) +{ +   unsigned int vertices[] = { 0, 5, 3 }; +   _bfs_tests(EINA_FALSE, vertices, (sizeof(vertices)/sizeof(*vertices))); +}  END_TEST -START_TEST (test_eina_graph_simple_dfs) +START_TEST (test_eina_graph_directed_bfs)  { +   unsigned int vertices[] = { 0, 5, 3 }; +   _bfs_tests(EINA_TRUE, vertices, (sizeof(vertices)/sizeof(*vertices))); +} +END_TEST + +static void _dfs_tests(Eina_Bool r, Eina_Bool directed, +                       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, EINA_FALSE); +   g = eina_graph_new(13, 2, directed);     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); - -   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 +100,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,16 +113,34 @@ START_TEST (test_eina_graph_simple_dfs)     ck_assert(eina_graph_shutdown() == 0);  } + +START_TEST (test_eina_graph_simple_dfs) +{ +   unsigned int v0[] = { 0, 5, 4, 3 }; +   unsigned int v1[] = { 0, 6, 4, 5, 3 }; +   _dfs_tests(EINA_TRUE, EINA_FALSE, v0, (sizeof(v0)/sizeof(*v0))); +   _dfs_tests(EINA_FALSE, EINA_FALSE, v1, (sizeof(v1)/sizeof(*v1))); +} +END_TEST + +START_TEST (test_eina_graph_directed_dfs) +{ +   unsigned int v0[] = { 0, 5, 4, 3 }; +   unsigned int v1[] = { 0, 6, 4, 3 }; +   _dfs_tests(EINA_TRUE, EINA_TRUE, v0, (sizeof(v0)/sizeof(*v0))); +   _dfs_tests(EINA_FALSE, EINA_TRUE, v1, (sizeof(v1)/sizeof(*v1))); +}  END_TEST  START_TEST (test_eina_graph_simple)  {     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, EINA_FALSE); +   g = eina_graph_new(13, 2, EINA_FALSE);     ck_assert(g != NULL);     _feed_simple_graph(g); @@ -157,12 +172,25 @@ 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);     eina_graph_free(g); +   ck_assert(eina_graph_shutdown() == 1); +   ck_assert(eina_graph_shutdown() == 0); +} +END_TEST + +START_TEST (test_eina_graph_directed) +{ +   FILE *outf; +   Eina_Graph *g; + +   ck_assert(eina_graph_init() == 1); +   ck_assert(eina_graph_init() == 2); +     g = eina_graph_new(13, 2, EINA_TRUE);     ck_assert(g != NULL); @@ -195,7 +223,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_directed.dot", "w"); +   outf = fopen("./eina_graph_directed.dot", "w");     eina_graph_dot_write(g, outf);     fclose(outf); @@ -209,19 +237,32 @@ 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 ("Simple Graph"); +   tcase_add_test (tc, test_eina_graph_simple); +   suite_add_tcase (s, tc); + +   tc = tcase_create ("Directed Graph"); +   tcase_add_test (tc, test_eina_graph_directed); +   suite_add_tcase (s, tc); + +   tc = tcase_create ("Simple Graph DFS"); +   tcase_add_test (tc, test_eina_graph_simple_dfs); +   suite_add_tcase (s, tc); + +   tc = tcase_create ("Directed Graph DFS"); +   tcase_add_test (tc, test_eina_graph_directed_dfs); +   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 ("Simple Graph BFS"); +   tcase_add_test (tc, test_eina_graph_simple_bfs); +   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 ("Directed Graph BFS"); +   tcase_add_test (tc, test_eina_graph_directed_bfs); +   suite_add_tcase (s, tc);     return s;  }  | 
