mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 15:56:52 +08:00
add_edge调试通过,后续再区分是有向图还是无向图
This commit is contained in:
parent
f63aa4db0a
commit
c411ee96eb
11
src/graph.c
11
src/graph.c
@ -625,16 +625,16 @@ static bool graph_add_edge(struct _graph* self, void* from, void* to, uint32_t w
|
||||
return false;
|
||||
}
|
||||
|
||||
to_node = find_node(self, from);
|
||||
to_node = find_node(self, to);
|
||||
if (to_node == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("print from and to obj start \n");
|
||||
self->print_obj(from_node->obj);
|
||||
self->print_obj(to_node->obj);
|
||||
printf("print from and to obj end \n");
|
||||
// printf("print from and to obj start \n");
|
||||
// self->print_obj(from_node->obj);
|
||||
// self->print_obj(to_node->obj);
|
||||
// printf("print from and to obj end \n");
|
||||
|
||||
// from_node add edge
|
||||
struct _graph_edge* new_edge = graph_edge_new(to_node, weight);
|
||||
@ -653,6 +653,7 @@ static bool graph_add_edge(struct _graph* self, void* from, void* to, uint32_t w
|
||||
}
|
||||
|
||||
// if graph is undirected
|
||||
// to_node add edge
|
||||
struct _graph_edge* new_edge2 = graph_edge_new(from_node, weight);
|
||||
if (new_edge2 == NULL)
|
||||
{
|
||||
|
@ -93,8 +93,8 @@ void test_graph_add_edge(void)
|
||||
|
||||
// test add_edge
|
||||
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[0], &data[1], 55));
|
||||
// TEST_ASSERT_TRUE(graph->add_edge(graph, &data[0], &data[2], 66));
|
||||
// TEST_ASSERT_TRUE(graph->add_edge(graph, &data[1], &data[3], 77));
|
||||
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[0], &data[2], 66));
|
||||
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[1], &data[3], 77));
|
||||
graph->print(graph);
|
||||
|
||||
TEST_ASSERT_FALSE(graph->add_edge(graph, &temp, &data[1], 0));
|
||||
|
Loading…
Reference in New Issue
Block a user