Skip to content

Commit

Permalink
Split nest_test_data into data and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvierjahn committed Mar 29, 2018
1 parent 94778bc commit f30db1f
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 273 deletions.
60 changes: 60 additions & 0 deletions niv/include/niv/testing/conduit_schema.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//------------------------------------------------------------------------------
// nest in situ vis
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualisation Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------

#ifndef NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_
#define NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_

namespace niv {
namespace testing {
namespace conduit_schema {

template <typename T>
inline std::string OpenTag(T tag) {
std::stringstream s;
s << '\"' << tag << '\"' << ":{ \n";
return s.str();
}

inline std::string CloseTag() { return std::string("} \n"); }
inline std::string CloseTagNext() { return std::string("}, \n"); }

inline std::string DoubleData(std::size_t offset) {
std::stringstream s;
s << "dtype:float64, ";
s << "number_of_elements:1, ";
s << "offset:" << offset << ", ";
s << "stride:8, ";
s << "element_bytes:8";
s << "\n";
return s.str();
}

inline void RemoveNextIndicator(std::stringstream* s) {
s->clear();
s->seekp(s->str().size() - 3);
*s << " \n";
}

} // namespace conduit_schema
} // namespace testing
} // namespace niv

#endif // NIV_INCLUDE_NIV_TESTING_CONDUIT_SCHEMA_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,21 @@
// limitations under the License.
//------------------------------------------------------------------------------

#ifndef NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_
#define NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_
#ifndef NIV_INCLUDE_NIV_TESTING_DATA_HPP_
#define NIV_INCLUDE_NIV_TESTING_DATA_HPP_

#include <string>
#include <vector>

#include "niv/producer/nest_multimeter.hpp"

namespace niv {

class Testing {
public:
Testing() = delete;
Testing(const Testing&) = delete;
Testing(Testing&&) = delete;
~Testing() = delete;

Testing& operator=(const Testing&) = delete;
Testing& operator=(Testing&&) = delete;
};
#include "niv/testing/conduit_schema.hpp"

namespace niv {
namespace testing {

class Data;

#if defined __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
Expand Down Expand Up @@ -126,14 +118,14 @@ inline std::string PathFor(const std::string& device_name,
}

// clang-format off
static const std::vector<double> ANY_VALUES{
static const std::vector<double> ANY_DATA_VALUES{
0.111, 0.112, 0.113, 0.121, 0.122, 0.123, 0.131, 0.132, 0.133,
0.211, 0.212, 0.213, 0.221, 0.222, 0.223, 0.231, 0.232, 0.233,
0.311, 0.312, 0.313, 0.321, 0.322, 0.323, 0.331, 0.332, 0.333};
// clang-format on
static const double ANY_VALUE{ANY_VALUES[0]};
static const std::vector<double> ANY_VALUES_FOR_ATTRIBUTES{
ANY_VALUES[0], ANY_VALUES[3], ANY_VALUES[6]};
static const double ANY_DATA_VALUE{ANY_DATA_VALUES[0]};
static const std::vector<double> ANY_DATA_VALUES_FOR_ATTRIBUTES{
ANY_DATA_VALUES[0], ANY_DATA_VALUES[3], ANY_DATA_VALUES[6]};

static const std::size_t TIME_STRIDE{9};
static const std::size_t ATTRIBUTE_STRIDE{3};
Expand All @@ -144,7 +136,7 @@ inline double ValueAt(std::size_t time_id, std::size_t attribute_id,
const std::size_t index = time_id * TIME_STRIDE +
attribute_id * ATTRIBUTE_STRIDE +
neuron_id * ID_STRIDE;
return ANY_VALUES[index];
return ANY_DATA_VALUES[index];
}

static const std::size_t ANY_TIME_OFFSET{ANY_INDEX * niv::testing::TIME_STRIDE};
Expand All @@ -165,81 +157,42 @@ static const std::size_t THIRD_ID_OFFSET{THIRD_INDEX * niv::testing::ID_STRIDE};
static const std::vector<std::size_t> ID_OFFSETS{
ANY_ID_OFFSET, ANOTHER_ID_OFFSET, THIRD_ID_OFFSET};

template <typename T>
inline std::string OpenTag(T tag) {
std::stringstream s;
s << '\"' << tag << '\"' << ":{ \n";
return s.str();
}

inline std::string CloseTag() { return std::string("} \n"); }
inline std::string CloseTagNext() { return std::string("}, \n"); }

inline std::string DoubleData(std::size_t offset) {
std::stringstream s;
s << "dtype:float64, ";
s << "number_of_elements:1, ";
s << "offset:" << offset << ", ";
s << "stride:8, ";
s << "element_bytes:8";
s << "\n";
return s.str();
}

inline void RemoveNextIndicator(std::stringstream* s) {
s->clear();
s->seekp(s->str().size() - 3);
*s << " \n";
}

inline static const std::string AnyNestDataSchema() {
std::stringstream s;
std::size_t offset = 0;
const std::size_t datum_size = 8;
s << "{\n";
s << " " << OpenTag(ANY_MULTIMETER_NAME);
s << " " << conduit_schema::OpenTag(ANY_MULTIMETER_NAME);
for (auto time : ANY_TIMES) {
s << " " << OpenTag(time);
s << " " << conduit_schema::OpenTag(time);
for (auto attribute : ANY_ATTRIBUTES) {
s << " " << OpenTag(attribute);
s << " " << conduit_schema::OpenTag(attribute);
for (auto id : ANY_IDS) {
s << " " << OpenTag(id);
s << " " << DoubleData((offset++) * datum_size);
s << " " << CloseTagNext();
s << " " << conduit_schema::OpenTag(id);
s << " "
<< conduit_schema::DoubleData((offset++) * datum_size);
s << " " << conduit_schema::CloseTagNext();
}
RemoveNextIndicator(&s);
s << " " << CloseTagNext();
conduit_schema::RemoveNextIndicator(&s);
s << " " << conduit_schema::CloseTagNext();
}
RemoveNextIndicator(&s);
s << " " << CloseTagNext();
conduit_schema::RemoveNextIndicator(&s);
s << " " << conduit_schema::CloseTagNext();
}
RemoveNextIndicator(&s);
s << " " << CloseTag();
conduit_schema::RemoveNextIndicator(&s);
s << " " << conduit_schema::CloseTag();
s << "}";
return s.str();
}

static conduit::Node ANY_NEST_DATA{
AnyNestDataSchema(), const_cast<double*>(ANY_VALUES.data()), false};
AnyNestDataSchema(), const_cast<double*>(ANY_DATA_VALUES.data()), false};

#if defined __GNUC__
#pragma GCC diagnostic pop
#endif

void Send(const conduit::Node& node);

conduit::Node AnyNode();

conduit::Node AnotherNode();

conduit::Node Update();

conduit::Node UpdatedNode();
conduit::Node UpdatedNodeAllZeros();

conduit::Node ADifferentNode();

} // namespace testing
} // namespace niv

#endif // NIV_INCLUDE_NIV_NEST_TEST_DATA_HPP_
#endif // NIV_INCLUDE_NIV_TESTING_DATA_HPP_
57 changes: 57 additions & 0 deletions niv/include/niv/testing/helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//------------------------------------------------------------------------------
// nest in situ vis
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualisation Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------

#ifndef NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_
#define NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_

#include "conduit/conduit_node.hpp"

namespace niv {
namespace testing {

class Helpers;

void Send(const conduit::Node& node);

conduit::Node AnyNode();
conduit::Node AnotherNode();

conduit::Node AnyUpdate();
conduit::Node UpdatedNode();
conduit::Node UpdatedNodeAllZeros();

conduit::Node ADifferentNode();

static const conduit::Node ANY_NODE{AnyNode()};
static const conduit::Node ANOTHER_NODE{AnotherNode()};

static const conduit::Node ANY_UPDATE{AnyUpdate()};
static const conduit::Node UPDATED_NODE{UpdatedNode()};
static const conduit::Node UPDATED_NODE_ALL_ZEROS{UpdatedNodeAllZeros()};

static const conduit::Node A_DIFFERENT_NODE{ADifferentNode()};

static const double ANY_VALUE{4.123};

} // namespace testing
} // namespace niv

#endif // NIV_INCLUDE_NIV_TESTING_HELPERS_HPP_
2 changes: 1 addition & 1 deletion niv/src/consumer/arbor_multimeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "conduit/conduit_node.hpp"

#include "niv/testing/nest_test_data.hpp"
#include "niv/testing/data.hpp"

namespace niv {
namespace consumer {
Expand Down
55 changes: 1 addition & 54 deletions niv/src/testing/nest_test_data.cpp → niv/src/testing/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// limitations under the License.
//------------------------------------------------------------------------------

#include "niv/testing/nest_test_data.hpp"
#include "niv/testing/data.hpp"

#include <string>
#include <vector>
Expand Down Expand Up @@ -59,58 +59,5 @@ std::vector<double> ThirdAttributesValues(double time) {

std::string AnyMultimeterName() { return "multimeter A"; }

void Send(const conduit::Node& node) {
exchange::RelaySharedMemory relay;
relay.Send(node);
}

conduit::Node AnyNode() {
conduit::Node node;
node["A/B/C"] = 3.1415;
node["A/B/D"] = 4.124;
node["A/E"] = 42.0;
return node;
}

conduit::Node AnotherNode() {
conduit::Node node;
node["A/B/C"] = 2.0 * 3.1415;
node["A/B/D"] = 3.0 * 4.124;
node["A/E"] = 4.0 * 42.0;
return node;
}

conduit::Node Update() {
conduit::Node node;
node["A/B/F"] = 2.0 * 3.1415;
node["A/B/G"] = 3.0 * 4.124;
node["A/H"] = 4.0 * 42.0;
return node;
}

conduit::Node UpdatedNode() {
conduit::Node node;
node["A/B/C"] = 3.1415;
node["A/B/D"] = 4.124;
node["A/E"] = 42.0;
node["A/B/F"] = 2.0 * 3.1415;
node["A/B/G"] = 3.0 * 4.124;
node["A/H"] = 4.0 * 42.0;
return node;
}

conduit::Node UpdatedNodeAllZeros() {
conduit::Node node;
node["A/B/C"] = 0.0;
node["A/B/D"] = 0.0;
node["A/E"] = 0.0;
node["A/B/F"] = 0.0;
node["A/B/G"] = 0.0;
node["A/H"] = 0.0;
return node;
}

conduit::Node ADifferentNode() { return Update(); }

} // namespace testing
} // namespace niv
Loading

0 comments on commit f30db1f

Please sign in to comment.