47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include "c_Test.h"
|
|||
|
|
#include "c_Digraph.h"
|
||
|
|
#include "c_NonrecursiveDirectedCycle.h"
|
||
|
|
#include "c_VertexIdList.h"
|
||
|
|
|
||
|
|
TEST_CASE(test_nonrecursive_cycle_detection) {
|
||
|
|
c_Digraph_t g;
|
||
|
|
c_Digraph_Init(&g, 3, NULL);
|
||
|
|
|
||
|
|
/* Construct an evaluation loop: 0 -> 1 -> 2 -> 0 */
|
||
|
|
c_Digraph_AddEdge(&g, 0, 1);
|
||
|
|
c_Digraph_AddEdge(&g, 1, 2);
|
||
|
|
c_Digraph_AddEdge(&g, 2, 0);
|
||
|
|
|
||
|
|
c_NonrecursiveDirectedCycle_t detector;
|
||
|
|
c_err_t err = c_NonrecursiveDirectedCycle_Init(&detector, &g, NULL);
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
|
||
|
|
ASSERT_TRUE(c_NonrecursiveDirectedCycle_HasCycle(&detector));
|
||
|
|
|
||
|
|
c_VertexIdList_t extracted;
|
||
|
|
c_VertexIdList_Init(&extracted, 0, NULL);
|
||
|
|
|
||
|
|
err = c_NonrecursiveDirectedCycle_GetCycle(&detector, &extracted);
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
|
||
|
|
/* Assert structural consistency (Loops through 4 steps back to index root origin) */
|
||
|
|
ASSERT_INT_EQ(4, c_VertexIdList_GetSize(&extracted));
|
||
|
|
|
||
|
|
c_VertexIdList_Destroy(&extracted);
|
||
|
|
c_NonrecursiveDirectedCycle_Destroy(&detector);
|
||
|
|
c_Digraph_Destroy(&g);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
int main(int argc, char** argv){
|
||
|
|
|
||
|
|
TEST_START(Component Tests);
|
||
|
|
|
||
|
|
// Execution list configurations
|
||
|
|
RUN_TEST(test_nonrecursive_cycle_detection);
|
||
|
|
|
||
|
|
TEST_REPORT();
|
||
|
|
|
||
|
|
RETURN_TEST_STATUS;
|
||
|
|
}
|