diff --git a/src/algorithms.hpp b/src/algorithms.hpp index 5456417ddaea0e0fe6c4e777a0fa8ebf3344c2ed..37eeaf370acd54ef326f70cc4ae17e46f1c6f2b0 100644 --- a/src/algorithms.hpp +++ b/src/algorithms.hpp @@ -139,8 +139,9 @@ std::vector<typename C::value_type> child_count(const C& parent_index) template<typename C> bool has_contiguous_compartments(const C& parent_index) { + using value_type = typename C::value_type; static_assert( - std::is_integral<typename C::value_type>::value, + std::is_integral<value_type>::value, "integral type required" ); @@ -149,9 +150,9 @@ bool has_contiguous_compartments(const C& parent_index) } auto num_child = child_count(parent_index); - for (auto i = 1u; i < parent_index.size(); ++i) { + for (auto i=1u; i < parent_index.size(); ++i) { auto p = parent_index[i]; - if (num_child[p] == 1 && p != i-1) { + if (num_child[p]==1 && p!=value_type(i-1)) { return false; } } diff --git a/tests/global_communication/test_exporter_spike_file.cpp b/tests/global_communication/test_exporter_spike_file.cpp index 85065a0c64b81be75a6797ffde8eb3308546210b..f7ba93571ad39fd6578ccc21949b073faebb93c2 100644 --- a/tests/global_communication/test_exporter_spike_file.cpp +++ b/tests/global_communication/test_exporter_spike_file.cpp @@ -8,21 +8,17 @@ #include <communication/communicator.hpp> #include <communication/global_policy.hpp> -#include <communication/exporter_spike_file.hpp> +#include <io/exporter_spike_file.hpp> -class exporter_spike_file_fixture : public ::testing::Test -{ +class exporter_spike_file_fixture : public ::testing::Test { protected: using time_type = float; using communicator_type = nest::mc::communication::global_policy; - using spike_type = - nest::mc::communication::exporter_spike_file<time_type, - communicator_type>::spike_type; + using exporter_type = + nest::mc::io::exporter_spike_file<time_type, communicator_type>; + using spike_type = exporter_type::spike_type; - using exporter_type = - nest::mc::communication::exporter_spike_file<time_type, - communicator_type>; std::string file_name; std::string path; std::string extention; @@ -35,68 +31,60 @@ protected: index(0) {} - std::string get_standard_file_name() - { + std::string get_standard_file_name() { return exporter_type::create_output_file_path( file_name, path, extention, 0); } - void SetUp() - { + void SetUp() { // code here will execute just before the test ensues } - void TearDown() - { + void TearDown() { // delete the start create file std::remove(get_standard_file_name().c_str()); } - ~exporter_spike_file_fixture() + ~exporter_spike_file_fixture() {} }; -TEST_F(exporter_spike_file_fixture, constructor) -{ +TEST_F(exporter_spike_file_fixture, constructor) { exporter_type exporter(file_name, path, extention, true); //test if the file exist and depending on over_write throw or delete std::ifstream f(get_standard_file_name()); - EXPECT_TRUE(f.good()); // We now know the file exists, so create a new exporter with overwrite false - try - { + try { exporter_type exporter1(file_name, path, extention, false); FAIL() << "expected a file already exists error"; } - catch (std::runtime_error const & err) - { - EXPECT_EQ(err.what(), std::string("Tried opening file for writing but it exists and over_write is false: " + - get_standard_file_name())); + catch (std::runtime_error const & err) { + EXPECT_EQ( + err.what(), + std::string("Tried opening file for writing but it exists and over_write is false: " + + get_standard_file_name()) + ); } catch (...) { FAIL() << "expected a file already exists error"; } } -TEST_F(exporter_spike_file_fixture, create_output_file_path) -{ +TEST_F(exporter_spike_file_fixture, create_output_file_path) { // Create some random paths, no need for fancy tests here std::string produced_filename = - exporter_type::create_output_file_path( - "spikes", "./", "gdf", 0); + exporter_type::create_output_file_path("spikes", "./", "gdf", 0); EXPECT_STREQ(produced_filename.c_str(), "./spikes_0.gdf"); produced_filename = - exporter_type::create_output_file_path( - "a_name", "../../", "txt", 5); + exporter_type::create_output_file_path("a_name", "../../", "txt", 5); EXPECT_STREQ(produced_filename.c_str(), "../../a_name_5.txt"); } -TEST_F(exporter_spike_file_fixture, do_export) -{ +TEST_F(exporter_spike_file_fixture, do_export) { { exporter_type exporter(file_name, path, extention); @@ -108,8 +96,9 @@ TEST_F(exporter_spike_file_fixture, do_export) spikes.push_back({ { 1, 0 }, 1.1 }); // now do the export - exporter.do_export(spikes); - } // Force destruction of exporter and explicit flush of the stream + exporter.output(spikes); + } + // Test if we have spikes in the file? std::ifstream f(get_standard_file_name()); EXPECT_TRUE(f.good()); diff --git a/tests/unit/test_algorithms.cpp b/tests/unit/test_algorithms.cpp index ebe19c3752e9e4eacb23008e467bca9a1fd95f79..2e82bcc9a6effc4e0fdbb70bbad3d7cddf443aba 100644 --- a/tests/unit/test_algorithms.cpp +++ b/tests/unit/test_algorithms.cpp @@ -244,9 +244,9 @@ TEST(algorithms, has_contiguous_compartments) // // 0 - // / \ + // / \. // 1 2 - // / \ + // / \. // 3 4 // EXPECT_TRUE(