diff --git a/test/incremental_bfs_test.cpp b/test/incremental_bfs_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3afa759207f762f0115de2ad504f7671c5122cb4 --- /dev/null +++ b/test/incremental_bfs_test.cpp @@ -0,0 +1,48 @@ +#include <vector> + +#include <catch2/catch.hpp> + +#include <gp-bnb/incremental_bfs.hpp> +#include <gp-bnb/graph.hpp> +#include <gp-bnb/metis_reader.hpp> + +// Tests for Incremental BFS Max Flow algorithm + +TEST_CASE("IncrementalBFSMaxFlow") { + + std::vector<std::vector<node_id>> adjacency_list { + { 2, 7 }, // 1 + { 1, 3, 4 }, // 2 + { 2, 5 }, // 3 + { 2, 5 }, // 4 + { 3, 4, 6}, // 5 + { 5, 8 }, // 6 + { 1, 8 }, // 7 + { 6, 7 } // 8 + }; + + graph g (adjacency_list) ; + + std::vector<node_id> sources { 1 }; + std::vector<node_id> sinks { 8 }; + incremental_bfs ibfs = incremental_bfs(g, sources, sinks); + + ibfs.run(); + int max_flow = ibfs.get_max_flow(); + + REQUIRE(max_flow == 2); + + std::string graph_file = "../test/inputs/tiny_01.graph"; + graph g2 = metis_reader().read(graph_file); + + std::vector<node_id> sources2 { 1 }; + std::vector<node_id> sinks2 { 7 }; + + incremental_bfs ibfs2 = incremental_bfs(g2, sources2, sinks2); + + ibfs2.run(); + int max_flow2 = ibfs2.get_max_flow(); + + REQUIRE(max_flow2 == 2); + +} diff --git a/test/meson.build b/test/meson.build index 819d301c3a61f20db09cc5fcbf4b46674aa98059..f7c8829f4d667c08331fcb1c8acdd7303ea454fa 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,11 +3,14 @@ testexe = executable( 'graph_test.cpp', 'reader_test.cpp', 'edmonds_karp_test.cpp', + 'incremental_bfs_test.cpp', 'bnb_test.cpp', # tests source files to be compiled '../bnb/graph.cpp', '../bnb/partition.cpp', '../bnb/metis_reader.cpp', '../bnb/edmonds_karp.cpp', + '../bnb/incremental_bfs.cpp', + '../bnb/ibfs_subtree.cpp', '../bnb/bnb.cpp', include_directories : inc) # declared include directories in root :code:`meson.build`