-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test for reading a network from file
- Loading branch information
1 parent
fd1f00f
commit 5143d58
Showing
3 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "catch2/matchers/catch_matchers.hpp" | ||
#include "network.hpp" | ||
#include "network_generation.hpp" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
#include <catch2/matchers/catch_matchers_range_equals.hpp> | ||
|
||
#include <config_parser.hpp> | ||
#include <filesystem> | ||
#include <simulation.hpp> | ||
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<std::vector<int>> neighbours_expected = { { 2, 1 }, {}, { 1 } }; | ||
std::vector<std::vector<Network::WeightT>> 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 ) ) ); | ||
} | ||
} |