Graph
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include "c_Bipartite.h"
|
||||
#include "c_Test.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
TEST_CASE(test_c_bipartite_classification) {
|
||||
// Test Scenario A: Valid Bipartite Structure (Square structure: 0-1, 1-2, 2-3, 3-0)
|
||||
c_Graph_t g_bipartite;
|
||||
c_Graph_Init(&g_bipartite, 4, 0);
|
||||
c_Graph_AddEdge(&g_bipartite, 0, 1);
|
||||
c_Graph_AddEdge(&g_bipartite, 1, 2);
|
||||
c_Graph_AddEdge(&g_bipartite, 2, 3);
|
||||
c_Graph_AddEdge(&g_bipartite, 3, 0);
|
||||
|
||||
c_Bipartite_t b1;
|
||||
c_err_t err = c_Bipartite_Init(&b1, &g_bipartite, 0);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
ASSERT_TRUE(c_Bipartite_IsBipartite(&b1));
|
||||
|
||||
// Neighbors must have matching complementary colored configurations
|
||||
ASSERT_TRUE(c_Bipartite_Color(&b1, 0) != c_Bipartite_Color(&b1, 1));
|
||||
ASSERT_TRUE(c_Bipartite_Color(&b1, 0) == c_Bipartite_Color(&b1, 2));
|
||||
|
||||
// Test Scenario B: Non-Bipartite Structure (Triangle layout containing odd cycle: 0-1, 1-2, 2-0)
|
||||
c_Graph_t g_invalid;
|
||||
c_Graph_Init(&g_invalid, 3, 0);
|
||||
c_Graph_AddEdge(&g_invalid, 0, 1);
|
||||
c_Graph_AddEdge(&g_invalid, 1, 2);
|
||||
c_Graph_AddEdge(&g_invalid, 2, 0);
|
||||
|
||||
c_Bipartite_t b2;
|
||||
err = c_Bipartite_Init(&b2, &g_invalid, 0);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
ASSERT_FALSE(c_Bipartite_IsBipartite(&b2)); // Must fail check validation rules
|
||||
|
||||
// Odd cycle array container details checking rules
|
||||
const c_VertexIdList_t* cyc = c_Bipartite_Cycle(&b2);
|
||||
ASSERT_PTR_NOT_NULL(cyc);
|
||||
ASSERT_TRUE(cyc->size > 0);
|
||||
|
||||
c_Bipartite_Destroy(&b1);
|
||||
c_Bipartite_Destroy(&b2);
|
||||
c_Graph_Destroy(&g_bipartite);
|
||||
c_Graph_Destroy(&g_invalid);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv){
|
||||
|
||||
TEST_START(Component Tests);
|
||||
|
||||
// Execution list configurations
|
||||
RUN_TEST(test_c_bipartite_classification);
|
||||
|
||||
TEST_REPORT();
|
||||
|
||||
RETURN_TEST_STATUS;
|
||||
}
|
||||
Reference in New Issue
Block a user