60 lines
2.0 KiB
C
60 lines
2.0 KiB
C
#include "c_EulerianCycle.h"
|
|
#include "c_Test.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
TEST_CASE(test_c_eulerian_cycle_detection) {
|
|
// Test Scenario A: Valid Eulerian Bowtie Figure-Eight Shape (5 vertices, all degrees are even)
|
|
c_Graph_t g_eulerian;
|
|
c_Graph_Init(&g_eulerian, 5, 0);
|
|
c_Graph_AddEdge(&g_eulerian, 0, 1);
|
|
c_Graph_AddEdge(&g_eulerian, 1, 2);
|
|
c_Graph_AddEdge(&g_eulerian, 2, 0); // Left Triangle loop closed
|
|
c_Graph_AddEdge(&g_eulerian, 2, 3);
|
|
c_Graph_AddEdge(&g_eulerian, 3, 4);
|
|
c_Graph_AddEdge(&g_eulerian, 4, 2); // Right Triangle loop closed
|
|
|
|
c_EulerianCycle_t ec1;
|
|
c_err_t err = c_EulerianCycle_Init(&ec1, &g_eulerian, 0);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
ASSERT_TRUE(c_EulerianCycle_HasCycle(&ec1));
|
|
|
|
const c_VertexIdList_t* path = c_EulerianCycle_Path(&ec1);
|
|
ASSERT_PTR_NOT_NULL(path);
|
|
ASSERT_LL_EQ(7, path->size); // 6 edges requires a 7-vertex path timeline loop
|
|
|
|
// Verify it correctly maps back into a closed trail format
|
|
c_uint_t start, end;
|
|
c_VertexIdList_Get((c_VertexIdList_t*)path, 0, &start);
|
|
c_VertexIdList_Get((c_VertexIdList_t*)path, path->size - 1, &end);
|
|
ASSERT_LL_EQ(start, end);
|
|
|
|
// Test Scenario B: Non-Eulerian Shape (A simple 4-node line path 0-1-2-3: odd endpoints)
|
|
c_Graph_t g_invalid;
|
|
c_Graph_Init(&g_invalid, 4, 0);
|
|
c_Graph_AddEdge(&g_invalid, 0, 1);
|
|
c_Graph_AddEdge(&g_invalid, 1, 2);
|
|
c_Graph_AddEdge(&g_invalid, 2, 3);
|
|
|
|
c_EulerianCycle_t ec2;
|
|
err = c_EulerianCycle_Init(&ec2, &g_invalid, 0);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
ASSERT_FALSE(c_EulerianCycle_HasCycle(&ec2)); // Must fail boundary check
|
|
|
|
c_EulerianCycle_Destroy(&ec1);
|
|
c_EulerianCycle_Destroy(&ec2);
|
|
c_Graph_Destroy(&g_eulerian);
|
|
c_Graph_Destroy(&g_invalid);
|
|
}
|
|
|
|
int main(int argc, char** argv){
|
|
TEST_START(Component Tests);
|
|
|
|
// Execution list configurations
|
|
RUN_TEST(test_c_eulerian_cycle_detection);
|
|
|
|
TEST_REPORT();
|
|
|
|
RETURN_TEST_STATUS;
|
|
}
|