diff --git a/meson.build b/meson.build index 62a76db..8b3e7fb 100644 --- a/meson.build +++ b/meson.build @@ -25,12 +25,13 @@ exe = executable('seldon', sources_seldon + 'src/main.cpp', tests = [ - ['Test Tarjan', 'test/test_tarjan.cpp'], - ['Test DeGroot', 'test/test_deGroot.cpp'], - ['Test Activity Driven', 'test/test_activity.cpp'], - ['Test Network', 'test/test_network.cpp'], - ['Test Network Generation', 'test/test_network_generation.cpp'], - ['Test Sampling', 'test/test_sampling.cpp'], + ['Test_Tarjan', 'test/test_tarjan.cpp'], + ['Test_DeGroot', 'test/test_deGroot.cpp'], + ['Test_Activity Driven', 'test/test_activity.cpp'], + ['Test_Network', 'test/test_network.cpp'], + ['Test_Network Generation', 'test/test_network_generation.cpp'], + ['Test_Sampling', 'test/test_sampling.cpp'], + ['Test_IO', 'test/test_io.cpp'], ] Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2']) diff --git a/test/res/network.txt b/test/res/network.txt new file mode 100644 index 0000000..37a337f --- /dev/null +++ b/test/res/network.txt @@ -0,0 +1,4 @@ +# idx_agent,n_neighbors_in,indices_neighbors_in[...],weights_in[...] +0, 2, 2, 1, 0.1, -0.2 +1, 0 +2, 1, 1, 1.2 \ No newline at end of file diff --git a/test/test_io.cpp b/test/test_io.cpp new file mode 100644 index 0000000..5765946 --- /dev/null +++ b/test/test_io.cpp @@ -0,0 +1,35 @@ +#include "catch2/matchers/catch_matchers.hpp" +#include "network.hpp" +#include "network_generation.hpp" + +#include +#include +#include + +#include +#include +#include +namespace fs = std::filesystem; + +TEST_CASE( "Test reading in the network from a file", "[io_network]" ) +{ + using namespace Seldon; + using namespace Catch::Matchers; + + auto proj_root_path = fs::current_path(); + auto network_file = proj_root_path / fs::path( "test/res/network.txt" ); + + auto network = Seldon::generate_from_file( network_file ); + + REQUIRE( network->n_agents() == 3 ); + + std::vector> neighbours_expected = { { 2, 1 }, {}, { 1 } }; + std::vector> weights_expected = { { 0.1, -0.2 }, {}, { 1.2 } }; + + for( int i = 0; i < network->n_agents(); i++ ) + { + fmt::print( "{}", i ); + REQUIRE_THAT( neighbours_expected[i], Catch::Matchers::UnorderedRangeEquals( network->get_neighbours( i ) ) ); + REQUIRE_THAT( weights_expected[i], Catch::Matchers::UnorderedRangeEquals( network->get_weights( i ) ) ); + } +} \ No newline at end of file