mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
添加add_edge单元测试
This commit is contained in:
parent
49bc8b0cc4
commit
628df4c1a0
34
src/graph.c
34
src/graph.c
@ -457,23 +457,27 @@ static void graph_print(struct _graph *self)
|
|||||||
self->print_obj(cur->obj);
|
self->print_obj(cur->obj);
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
// printf("\n ");
|
printf("edge : \n");
|
||||||
// for(uint32_t i = 0; i < self->_capacity; i++)
|
cur = self->_head->next;
|
||||||
// {
|
while (cur != NULL)
|
||||||
// self->print_obj((char *)self->_head->obj + i * self->_obj_size);
|
{
|
||||||
// }
|
struct _graph_edge* edge = cur->edge;
|
||||||
// printf("\n");
|
while (edge != NULL)
|
||||||
// for(uint32_t i = 0; i < self->_capacity; i++)
|
{
|
||||||
// {
|
struct _graph_node* target = (struct _graph_node*)edge->target;
|
||||||
// self->print_obj((char *)self->_head->obj + i * self->_obj_size);
|
|
||||||
// for(uint32_t j = 0; j < self->_capacity; j++)
|
|
||||||
// {
|
|
||||||
// printf(" %2d ", self->_head->edge[i][j]);
|
|
||||||
// }
|
|
||||||
// printf("\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
printf("from ");
|
||||||
|
self->print_obj(cur->obj);
|
||||||
|
printf(" to ");
|
||||||
|
self->print_obj(target->obj);
|
||||||
|
printf(": %d \n", edge->weight);
|
||||||
|
edge = edge->next;
|
||||||
|
}
|
||||||
|
// self->print_obj(cur->obj);
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("print done.\n");
|
printf("print done.\n");
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,40 @@ void test_graph_add_vertex(void)
|
|||||||
TEST_ASSERT_NULL(graph);
|
TEST_ASSERT_NULL(graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_graph_add_edge(void)
|
||||||
|
{
|
||||||
|
const int size = 10;
|
||||||
|
int data[10] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||||
|
};
|
||||||
|
int temp = 11;
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
graph_t graph = graph_new(sizeof(int));
|
||||||
|
TEST_ASSERT_NOT_NULL(graph);
|
||||||
|
graph->compare = compare_num;
|
||||||
|
graph->print_obj = print_num;
|
||||||
|
|
||||||
|
// test add_vertex
|
||||||
|
for(i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_TRUE(graph->add_vertex(graph, &data[i]));
|
||||||
|
}
|
||||||
|
graph->print(graph);
|
||||||
|
|
||||||
|
// test add_edge
|
||||||
|
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[0], &data[1], 0));
|
||||||
|
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[0], &data[2], 0));
|
||||||
|
TEST_ASSERT_TRUE(graph->add_edge(graph, &data[1], &data[3], 0));
|
||||||
|
graph->print(graph);
|
||||||
|
|
||||||
|
TEST_ASSERT_FALSE(graph->add_edge(graph, &temp, &data[1], 0));
|
||||||
|
|
||||||
|
graph_free(&graph);
|
||||||
|
TEST_ASSERT_NULL(graph);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void test_graph_print(void)
|
void test_graph_print(void)
|
||||||
{
|
{
|
||||||
@ -116,6 +150,7 @@ void test_graph(void)
|
|||||||
|
|
||||||
RUN_TEST(test_graph_new);
|
RUN_TEST(test_graph_new);
|
||||||
RUN_TEST(test_graph_add_vertex);
|
RUN_TEST(test_graph_add_vertex);
|
||||||
|
RUN_TEST(test_graph_add_edge);
|
||||||
|
|
||||||
// RUN_TEST(test_graph_print);
|
// RUN_TEST(test_graph_print);
|
||||||
// RUN_TEST(test_graph_from_matrix);
|
// RUN_TEST(test_graph_from_matrix);
|
||||||
|
Loading…
Reference in New Issue
Block a user