49 lines
1.5 KiB
C
49 lines
1.5 KiB
C
#include "c_Test.h"
|
|
#include "c_EdgeWeightedGraph.h"
|
|
#include "c_BoruvkaMST.h"
|
|
#include "c_VertexIdList.h"
|
|
|
|
TEST_CASE(test_boruvka_mst_evaluation) {
|
|
c_EdgeWeightedGraph_t g;
|
|
c_err_t err = c_EdgeWeightedGraph_Init(&g, 4, NULL);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
|
|
/* Construct a generic evaluation cyclic graph:
|
|
* 0 - 1 (Weight: 1.0) -> Expected in MST
|
|
* 1 - 2 (Weight: 2.0) -> Expected in MST
|
|
* 2 - 3 (Weight: 3.0) -> Expected in MST
|
|
* 3 - 0 (Weight: 4.0) -> Skipped
|
|
* 0 - 2 (Weight: 5.0) -> Skipped
|
|
*/
|
|
c_EdgeWeightedGraph_AddEdge(&g, 0, 1, 1.0);
|
|
c_EdgeWeightedGraph_AddEdge(&g, 1, 2, 2.0);
|
|
c_EdgeWeightedGraph_AddEdge(&g, 2, 3, 3.0);
|
|
c_EdgeWeightedGraph_AddEdge(&g, 3, 0, 4.0);
|
|
c_EdgeWeightedGraph_AddEdge(&g, 0, 2, 5.0);
|
|
|
|
c_BoruvkaMST_t boruvka;
|
|
err = c_BoruvkaMST_Init(&boruvka, &g, 0);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
|
|
/* Minimal spanning total weight sum must equal 1.0 + 2.0 + 3.0 = 6.0 */
|
|
ASSERT_DOUBLE_EQ_MSG(6.0, c_BoruvkaMST_Weight(&boruvka), "Boruvka MST weight computation mismatch");
|
|
|
|
c_VertexIdList_t result_list;
|
|
c_VertexIdList_Init(&result_list, 0, 0);
|
|
|
|
err = c_BoruvkaMST_GetEdges(&boruvka, &result_list);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
ASSERT_INT_EQ(3, c_UIntArray_GetSize(&result_list));
|
|
|
|
c_VertexIdList_Destroy(&result_list);
|
|
c_BoruvkaMST_Destroy(&boruvka);
|
|
c_EdgeWeightedGraph_Destroy(&g);
|
|
}
|
|
|
|
int main(void) {
|
|
TEST_START(Boruvka_MST_Verification_Suite);
|
|
RUN_TEST(test_boruvka_mst_evaluation);
|
|
TEST_REPORT();
|
|
RETURN_TEST_STATUS;
|
|
}
|