diff --git a/test/test_network.cpp b/test/test_network.cpp index 47a0076..36f9fc8 100644 --- a/test/test_network.cpp +++ b/test/test_network.cpp @@ -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 buffer_n_get{}; // buffer for getting neighbours + std::vector buffer_w_get{}; // buffer for getting the weights + std::vector neigh{ { 0, 10 } }; // new neighbours + std::vector 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 buffer_n{ { 0, 10, 15 } }; - std::vector buffer_w{ 0.1, 0.2, 0.3 }; + std::vector buffer_n{ { 0, 10, 15 } }; // new neighbours + std::vector 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 buffer_n_get{}; - std::vector 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> old_edges; for( size_t i_agent = 0; i_agent < network->n_agents(); i_agent++ ) {