Graph
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include "c_Test.h"
|
||||
#include "c_Digraph.h"
|
||||
#include "c_DepthFirstOrder.h"
|
||||
#include "c_VertexIdList.h"
|
||||
|
||||
TEST_CASE(test_depth_first_order_streams) {
|
||||
c_Digraph_t g;
|
||||
c_err_t err = c_Digraph_Init(&g, 3, NULL);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
|
||||
/* Construct a simple DAG structure: 0 -> 1 -> 2 */
|
||||
c_Digraph_AddEdge(&g, 0, 1);
|
||||
c_Digraph_AddEdge(&g, 1, 2);
|
||||
|
||||
c_DepthFirstOrder_t order;
|
||||
err = c_DepthFirstOrder_Init(&order, &g, 0);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
|
||||
c_VertexIdList_t pre, post, rev_post;
|
||||
c_VertexIdList_Init(&pre,0, 0);
|
||||
c_VertexIdList_Init(&post,0, 0);
|
||||
c_VertexIdList_Init(&rev_post,0, 0);
|
||||
|
||||
ASSERT_INT_EQ(C_SUCCESS, c_DepthFirstOrder_GetPre(&order, &pre));
|
||||
ASSERT_INT_EQ(C_SUCCESS, c_DepthFirstOrder_GetPost(&order, &post));
|
||||
ASSERT_INT_EQ(C_SUCCESS, c_DepthFirstOrder_GetReversePost(&order, &rev_post));
|
||||
|
||||
/* Verify Pre-order (Should be 0, 1, 2) */
|
||||
c_uint_t val = 0;
|
||||
c_VertexIdList_Get(&pre, 0, &val); ASSERT_LL_EQ(0, val);
|
||||
c_VertexIdList_Get(&pre, 1, &val); ASSERT_LL_EQ(1, val);
|
||||
c_VertexIdList_Get(&pre, 2, &val); ASSERT_LL_EQ(2, val);
|
||||
|
||||
/* Verify Post-order (Should be 2, 1, 0) */
|
||||
c_VertexIdList_Get(&post, 0, &val); ASSERT_LL_EQ(2, val);
|
||||
c_VertexIdList_Get(&post, 1, &val); ASSERT_LL_EQ(1, val);
|
||||
c_VertexIdList_Get(&post, 2, &val); ASSERT_LL_EQ(0, val);
|
||||
|
||||
/* Verify Reverse Post-order / Topological Candidate (Should be 0, 1, 2) */
|
||||
c_VertexIdList_Get(&rev_post, 0, &val); ASSERT_LL_EQ(0, val);
|
||||
c_VertexIdList_Get(&rev_post, 1, &val); ASSERT_LL_EQ(1, val);
|
||||
c_VertexIdList_Get(&rev_post, 2, &val); ASSERT_LL_EQ(2, val);
|
||||
|
||||
c_VertexIdList_Destroy(&pre);
|
||||
c_VertexIdList_Destroy(&post);
|
||||
c_VertexIdList_Destroy(&rev_post);
|
||||
c_DepthFirstOrder_Destroy(&order);
|
||||
c_Digraph_Destroy(&g);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* 启动测试集 */
|
||||
TEST_START(Tests);
|
||||
|
||||
/* 运行具体的测试用例 */
|
||||
RUN_TEST(test_depth_first_order_streams);
|
||||
|
||||
/* 打印测试汇总报告 */
|
||||
TEST_REPORT();
|
||||
|
||||
/* 返回测试状态代码码(0 代表全部通过,1 代表有失败) */
|
||||
RETURN_TEST_STATUS;
|
||||
}
|
||||
Reference in New Issue
Block a user