This commit is contained in:
2026-09-07 18:48:16 +08:00
parent 1564716731
commit c945aa211f
138 changed files with 10337 additions and 150 deletions
+59
View File
@@ -0,0 +1,59 @@
#include "c_CC.h"
#include "c_Test.h"
#include <stdlib.h>
#include <stdio.h>
TEST_CASE(test_c_cc_streamlined_queries) {
c_Graph_t graph;
c_Graph_Init(&graph, 6, 0);
// Component 0: Vertices {0, 1, 2}
c_Graph_AddEdge(&graph, 0, 1);
c_Graph_AddEdge(&graph, 1, 2);
// Component 1: Vertices {3, 4}
c_Graph_AddEdge(&graph, 3, 4);
// Component 2: Vertex {5} (Isolated)
c_CC_t cc;
c_err_t err = c_CC_Init(&cc, &graph, 0);
ASSERT_INT_EQ(C_SUCCESS, err);
// Verify your clean standalone queries (Notice: no graph pointers needed here!)
ASSERT_LL_EQ(3, c_CC_Count(&cc));
// Test connectivity groupings
ASSERT_TRUE(c_CC_Connected(&cc, 0, 2));
ASSERT_TRUE(c_CC_Connected(&cc, 3, 4));
ASSERT_FALSE(c_CC_Connected(&cc, 1, 5));
// Test partition tracking sizes
ASSERT_LL_EQ(3, c_CC_Size(&cc, 0)); // Component 0 contains 3 vertices
ASSERT_LL_EQ(2, c_CC_Size(&cc, 3)); // Component 1 contains 2 vertices
ASSERT_LL_EQ(1, c_CC_Size(&cc, 5)); // Component 2 contains 1 vertex
// Test unique component ID mapping invariants
ASSERT_LL_EQ(c_CC_Id(&cc, 0), c_CC_Id(&cc, 2));
ASSERT_TRUE(c_CC_Id(&cc, 1) != c_CC_Id(&cc, 4));
// Test out of bounds security protection filters
ASSERT_FALSE(c_CC_Connected(&cc, 0, 999));
ASSERT_LL_EQ(0, c_CC_Id(&cc, 999));
c_CC_Destroy(&cc);
c_Graph_Destroy(&graph);
}
int main(int argc, char** argv){
TEST_START(c_CC Component Tests);
// Execution list configurations
RUN_TEST(test_c_cc_streamlined_queries);
TEST_REPORT();
RETURN_TEST_STATUS;
}