43 lines
1.5 KiB
C
43 lines
1.5 KiB
C
#include "c_Test.h"
|
|
#include "c_FordFulkerson.h"
|
|
|
|
TEST_CASE(test_ford_fulkerson_max_flow_and_min_cut) {
|
|
c_FlowNetwork_t network;
|
|
c_err_t err = c_FlowNetwork_Init(&network, 4, NULL);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
|
|
/* Construct a standard flow distribution diamond network layout:
|
|
* 0 -> 1 (Capacity: 2.0)
|
|
* 0 -> 2 (Capacity: 3.0)
|
|
* 1 -> 3 (Capacity: 1.0)
|
|
* 2 -> 3 (Capacity: 4.0)
|
|
* 1 -> 2 (Capacity: 2.0, Cross diagonal distribution balance)
|
|
*/
|
|
c_FlowNetwork_AddEdge(&network, 0, 1, 2.0);
|
|
c_FlowNetwork_AddEdge(&network, 0, 2, 3.0);
|
|
c_FlowNetwork_AddEdge(&network, 1, 3, 1.0);
|
|
c_FlowNetwork_AddEdge(&network, 2, 3, 4.0);
|
|
c_FlowNetwork_AddEdge(&network, 1, 2, 2.0);
|
|
|
|
c_FordFulkerson_t ff;
|
|
err = c_FordFulkerson_Init(&ff, &network, 0, 3, &network.allocator);
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
|
|
|
/* Max-flow bottleneck saturation calculation verification must equal exactly 4.0 */
|
|
ASSERT_DOUBLE_EQ_MSG(4.0, c_FordFulkerson_GetValue(&ff), "Maximum flow metric validation failed");
|
|
|
|
/* Min-Cut Verification: check side assignments */
|
|
ASSERT_TRUE(c_FordFulkerson_InCut(&ff, 0)); /* Source must be on source side of cut */
|
|
ASSERT_FALSE(c_FordFulkerson_InCut(&ff, 3)); /* Sink must be on sink side of cut */
|
|
|
|
c_FordFulkerson_Destroy(&ff);
|
|
c_FlowNetwork_Destroy(&network);
|
|
}
|
|
|
|
int main(void) {
|
|
TEST_START(FordFulkerson_MaxFlow_Suite);
|
|
RUN_TEST(test_ford_fulkerson_max_flow_and_min_cut);
|
|
TEST_REPORT();
|
|
RETURN_TEST_STATUS;
|
|
}
|