Graph
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "c_DirectedDFS.h"
|
||||
#include "c_Test.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
TEST_CASE(test_directed_dfs_reachability) {
|
||||
c_Digraph_t g;
|
||||
c_Digraph_Init(&g, 6, NULL);
|
||||
|
||||
/* Construct a graph chain structure: 0 -> 1 -> 2 -> 3; and separate branch 4 -> 5 */
|
||||
c_Digraph_AddEdge(&g, 0, 1);
|
||||
c_Digraph_AddEdge(&g, 1, 2);
|
||||
c_Digraph_AddEdge(&g, 2, 3);
|
||||
c_Digraph_AddEdge(&g, 4, 5);
|
||||
|
||||
/* 1. Run DFS starting from source vertex 0 */
|
||||
c_DirectedDFS_t dfs;
|
||||
c_err_t err = c_DirectedDFS_Init(&dfs, &g, 0, 0);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
|
||||
/* Verify Reachability mapping */
|
||||
ASSERT_TRUE(c_DirectedDFS_HasPathTo(&dfs, 0, g.V));
|
||||
ASSERT_TRUE(c_DirectedDFS_HasPathTo(&dfs, 3, g.V));
|
||||
ASSERT_FALSE(c_DirectedDFS_HasPathTo(&dfs, 4, g.V)); /* Isolated from 0 */
|
||||
ASSERT_INT_EQ(4, c_DirectedDFS_GetCount(&dfs)); /* 0, 1, 2, 3 are found */
|
||||
|
||||
c_DirectedDFS_Destroy(&dfs);
|
||||
c_Digraph_Destroy(&g);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv){
|
||||
|
||||
TEST_START(Component Tests);
|
||||
|
||||
// Execution list configurations
|
||||
RUN_TEST(test_directed_dfs_reachability);
|
||||
|
||||
TEST_REPORT();
|
||||
|
||||
RETURN_TEST_STATUS;
|
||||
}
|
||||
Reference in New Issue
Block a user