#include "c_Test.h" #include "c_Digraph.h" #include "c_DirectedEulerianCycle.h" #include "c_VertexIdList.h" TEST_CASE(test_directed_eulerian_cycle) { c_Digraph_t g; c_Digraph_Init(&g, 4, NULL); /* Construct a simple complete Eulerian directed graph: * 0 -> 1 -> 2 -> 0 * 2 -> 3 -> 2 (nested cycle hook) */ c_Digraph_AddEdge(&g, 0, 1); c_Digraph_AddEdge(&g, 1, 2); c_Digraph_AddEdge(&g, 2, 0); c_Digraph_AddEdge(&g, 2, 3); c_Digraph_AddEdge(&g, 3, 2); c_DirectedEulerianCycle_t eulerian; c_err_t err = c_DirectedEulerianCycle_Init(&eulerian, &g, NULL); ASSERT_INT_EQ(C_SUCCESS, err); /* Assert an Eulerian path cycle tour is verified */ ASSERT_TRUE(c_DirectedEulerianCycle_HasCycle(&eulerian)); c_VertexIdList_t tour_output; c_VertexIdList_Init(&tour_output, 0, NULL); err = c_DirectedEulerianCycle_GetCycle(&eulerian, &tour_output); ASSERT_INT_EQ(C_SUCCESS, err); /* Total path sequence elements count must equal exact E + 1 (5 edges + 1 = 6 steps) */ c_size_t cycle_steps = (c_size_t)c_VertexIdList_GetSize(&tour_output); ASSERT_LL_EQ(6, cycle_steps); /* First and last step points must align to form a valid complete tour loop boundary */ c_uint_t start_v = 0; c_uint_t end_v = 0; c_VertexIdList_Get(&tour_output, 0, &start_v); c_VertexIdList_Get(&tour_output, cycle_steps - 1, &end_v); ASSERT_LL_EQ(start_v, end_v); c_VertexIdList_Destroy(&tour_output); c_DirectedEulerianCycle_Destroy(&eulerian); c_Digraph_Destroy(&g); } int main(int argc, char** argv){ TEST_START(Component Tests); // Execution list configurations RUN_TEST(test_directed_eulerian_cycle); TEST_REPORT(); RETURN_TEST_STATUS; }