Graph
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include "c_Test.h"
|
||||
#include "c_EdgeWeightedGraph.h"
|
||||
|
||||
TEST_CASE(test_edge_weighted_graph_plumbing) {
|
||||
c_EdgeWeightedGraph_t graph;
|
||||
c_err_t err = c_EdgeWeightedGraph_Init(&graph, 3, NULL);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
|
||||
ASSERT_LL_EQ(3, c_EdgeWeightedGraph_GetV(&graph));
|
||||
ASSERT_LL_EQ(0, c_EdgeWeightedGraph_GetE(&graph));
|
||||
|
||||
/* Inject a single undirected connection step: 0 - 1 (Weight: 3.5) */
|
||||
err = c_EdgeWeightedGraph_AddEdge(&graph, 0, 1, 3.5);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
ASSERT_LL_EQ(1, c_EdgeWeightedGraph_GetE(&graph));
|
||||
|
||||
/* Inspect connectivity lists for index point 0 */
|
||||
c_AdjList_t* zero_adj = &graph.adj_list[0];
|
||||
ASSERT_INT_EQ(1, c_AdjList_GetSize(zero_adj));
|
||||
|
||||
c_uint_t generic_id = 0;
|
||||
err = c_AdjList_Get(zero_adj, 0, &generic_id);
|
||||
ASSERT_INT_EQ(C_SUCCESS, err);
|
||||
|
||||
/* Fetch edge references out from pool */
|
||||
c_Edge_t* resolved_edge = &graph.edges_pool[(c_size_t)generic_id];
|
||||
ASSERT_DOUBLE_EQ_MSG(3.5, c_Edge_Weight(resolved_edge), "Weight match failed");
|
||||
|
||||
/* Validate endpoints parsing */
|
||||
c_size_t start_node = c_Edge_Either(resolved_edge);
|
||||
ASSERT_LL_EQ(0, start_node);
|
||||
ASSERT_LL_EQ(1, c_Edge_Other(resolved_edge, start_node));
|
||||
|
||||
c_EdgeWeightedGraph_Destroy(&graph);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
TEST_START(EdgeWeightedGraph_Plumbing_Suite);
|
||||
RUN_TEST(test_edge_weighted_graph_plumbing);
|
||||
TEST_REPORT();
|
||||
RETURN_TEST_STATUS;
|
||||
}
|
||||
Reference in New Issue
Block a user