summaryrefslogtreecommitdiffstats
path: root/src/tests/eina_graph_suite.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-01-03 22:06:50 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-01-03 22:06:50 +0100
commit731a4848cd46ee02b012c601adc6ecb158a8718b (patch)
tree607dac4ae205dce7014cdb61eafdfa98fddeb753 /src/tests/eina_graph_suite.c
parent3d8c84ff7006e188538985fddf93847d275cf52a (diff)
downloadeina_graph-731a4848cd46ee02b012c601adc6ecb158a8718b.zip
eina_graph-731a4848cd46ee02b012c601adc6ecb158a8718b.tar.gz
add Eina_Graph_BFS tests
Diffstat (limited to 'src/tests/eina_graph_suite.c')
-rw-r--r--src/tests/eina_graph_suite.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c
index c187159..138d852 100644
--- a/src/tests/eina_graph_suite.c
+++ b/src/tests/eina_graph_suite.c
@@ -3,6 +3,7 @@
#endif /* HAVE_CONFIG_H */
#include <check.h>
+#include <limits.h>
#include "Eina_Graph.h"
static void
@@ -23,6 +24,45 @@ _feed_simple_graph(Eina_Graph *g)
ck_assert(eina_graph_edge_add(g, 5, 3) == EINA_TRUE);
}
+START_TEST (test_eina_graph_simple_bfs)
+{
+ 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);
+ ck_assert(g != NULL);
+
+ _feed_simple_graph(g);
+
+ bfs = eina_graph_bfs_new(g, 0);
+ ck_assert(eina_graph_bfs_source(bfs) == 0);
+ ck_assert(eina_graph_bfs_has_path_to(bfs, 12) == EINA_FALSE);
+ ck_assert(eina_graph_bfs_path_to(bfs, 12) == NULL);
+ ck_assert(eina_graph_bfs_path_to(bfs, 15) == NULL);
+ ck_assert(eina_graph_bfs_dist_to(bfs, 15) == UINT_MAX);
+ ck_assert(eina_graph_bfs_has_path_to(bfs, 3) == EINA_TRUE);
+ 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)));
+ i = 0;
+ EINA_LIST_FOREACH(path, l, data)
+ {
+ ck_assert(vsr[i] == CAST_D(data));
+ i++;
+ }
+ eina_graph_bfs_free(bfs);
+
+ eina_graph_free(g);
+
+ ck_assert(eina_graph_shutdown() == 0);
+}
+END_TEST
+
START_TEST (test_eina_graph_simple_dfs)
{
Eina_Graph_DFS *dfs;
@@ -133,6 +173,10 @@ eina_graph_suite (void)
tcase_add_test (tc_simple_dfs, test_eina_graph_simple_dfs);
suite_add_tcase (s, tc_simple_dfs);
+ 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);
+
return s;
}