Skip to content

Commit

Permalink
tests: Added a test for some network functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MSallermann committed Oct 18, 2023
1 parent 793bb6b commit c1e203f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions test/test_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,41 @@ TEST_CASE( "Testing the network class" )
// Does n_agents work?
REQUIRE( network->n_agents() == n_agents );

// Check that the function for setting neighbours and a single weight work
// Agent 3
std::vector<size_t> buffer_n_get{}; // buffer for getting neighbours
std::vector<Seldon::Network::WeightT> buffer_w_get{}; // buffer for getting the weights
std::vector<size_t> neigh{ { 0, 10 } }; // new neighbours
std::vector<Seldon::Network::WeightT> weight{ 0.5, 0.5 }; // new weights (const)
network->set_neighbours_and_weights( 3, neigh, 0.5 );
network->get_weights( 3, buffer_w_get );
REQUIRE_THAT( buffer_w_get, Catch::Matchers::UnorderedRangeEquals( buffer_w_get ) );

// Change the connections for agent 3
std::vector<size_t> buffer_n{ { 0, 10, 15 } };
std::vector<Seldon::Network::WeightT> buffer_w{ 0.1, 0.2, 0.3 };
std::vector<size_t> buffer_n{ { 0, 10, 15 } }; // new neighbours
std::vector<Seldon::Network::WeightT> buffer_w{ 0.1, 0.2, 0.3 }; // new weights
network->set_neighbours_and_weights( 3, buffer_n, buffer_w );

// Make sure the changes worked
std::vector<size_t> buffer_n_get{};
std::vector<Seldon::Network::WeightT> buffer_w_get{};
network->get_neighbours( 3, buffer_n_get );
network->get_weights( 3, buffer_w_get );

REQUIRE_THAT( buffer_n_get, Catch::Matchers::UnorderedRangeEquals( buffer_n ) );
REQUIRE_THAT( buffer_w_get, Catch::Matchers::UnorderedRangeEquals( buffer_w ) );

// Check that the push_back function works for agent 3
buffer_n.push_back( 5 ); // new neighbour
buffer_w.push_back( 1.0 ); // new weight for this new connection
network->push_back_neighbour_and_weight( 3, 5, 1.0 ); // new connection added with weight
// Check that the change worked for the push_back function
network->get_neighbours( 3, buffer_n_get );
network->get_weights( 3, buffer_w_get );
REQUIRE_THAT( buffer_n_get, Catch::Matchers::UnorderedRangeEquals( buffer_n ) );
REQUIRE_THAT( buffer_w_get, Catch::Matchers::UnorderedRangeEquals( buffer_w ) );

// Now we test the transpose() function

// First record all the old edges as tupels (i,j,w) where this edge goes from j -> i with weight w
// First record all the old edges as tuples (i,j,w) where this edge goes from j -> i with weight w
std::set<std::tuple<size_t, size_t, Network::WeightT>> old_edges;
for( size_t i_agent = 0; i_agent < network->n_agents(); i_agent++ )
{
Expand Down

0 comments on commit c1e203f

Please sign in to comment.