Graph
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include "c_NonrecursiveDFS.h"
|
||||
#include "c_Test.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
TEST_CASE(test_c_nonrecursive_dfs_component) {
|
||||
c_Graph_t graph;
|
||||
c_Graph_Init(&graph, 4, 0);
|
||||
|
||||
// Form line path network structure: 0-1, 1-2, 2-3
|
||||
c_Graph_AddEdge(&graph, 0, 1);
|
||||
c_Graph_AddEdge(&graph, 1, 2);
|
||||
c_Graph_AddEdge(&graph, 2, 3);
|
||||
|
||||
c_NonrecursiveDFS_t search;
|
||||
c_err_t err = c_NonrecursiveDFS_Init(&search, &graph, 0, 0);
|
||||
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
ASSERT_LL_EQ(4, c_NonrecursiveDFS_Count(&search)); // All nodes connected
|
||||
ASSERT_TRUE(c_NonrecursiveDFS_HasPathTo(&search, 3));
|
||||
|
||||
c_VertexIdList_t route;
|
||||
c_VertexIdList_Init(&route, 4, 0);
|
||||
|
||||
c_err_t path_err = c_NonrecursiveDFS_PathTo(&search, 3, &route);
|
||||
ASSERT_INT_EQ(C_SUCCESS, path_err);
|
||||
ASSERT_LL_EQ(4, route.size);
|
||||
|
||||
// Verify chronological order sequence matches properly: 0 -> 1 -> 2 -> 3
|
||||
c_uint_t node;
|
||||
c_VertexIdList_Get(&route, 0, &node); ASSERT_LL_EQ(0, node);
|
||||
c_VertexIdList_Get(&route, 3, &node); ASSERT_LL_EQ(3, node);
|
||||
|
||||
c_VertexIdList_Destroy(&route);
|
||||
c_NonrecursiveDFS_Destroy(&search);
|
||||
c_Graph_Destroy(&graph);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv){
|
||||
TEST_START(c_NonrecursiveDFS Component Tests);
|
||||
|
||||
// Execution list configurations
|
||||
RUN_TEST(test_c_nonrecursive_dfs_component);
|
||||
|
||||
TEST_REPORT();
|
||||
|
||||
RETURN_TEST_STATUS;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user