Skip to content
Snippets Groups Projects
Commit 319b7802 authored by w-klijn's avatar w-klijn Committed by GitHub
Browse files

Merge pull request #79 from eth-cscs/exporter_fixes

Exporter fixes
parents 5e2e6a6c 5e82f0c3
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
......
......@@ -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());
......
......@@ -244,9 +244,9 @@ TEST(algorithms, has_contiguous_compartments)
//
// 0
// / \
// / \.
// 1 2
// / \
// / \.
// 3 4
//
EXPECT_TRUE(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment