From 7ffed3d8908ac631c3e034c0fdc9d21be925c1ac Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 22 Sep 2023 09:31:41 +0200 Subject: [PATCH] Add first tests. --- test/CMakeLists.txt | 1 + test/unit_tests/utils/enumerate.cpp | 39 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/unit_tests/utils/enumerate.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0fb11833a2..729a95d771 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable( unit_tests/container/generic_data_handle.cpp unit_tests/container/mechanism.cpp unit_tests/container/node.cpp + unit_tests/utils/enumerate.cpp unit_tests/oc/hoc_interpreter.cpp) set(catch2_targets testneuron) if(NRN_ENABLE_THREADS) diff --git a/test/unit_tests/utils/enumerate.cpp b/test/unit_tests/utils/enumerate.cpp new file mode 100644 index 0000000000..6f703bd903 --- /dev/null +++ b/test/unit_tests/utils/enumerate.cpp @@ -0,0 +1,39 @@ +// Must appear before `enumerate.h` otherwise, std::begin and std::rbegin are +// undefined. This should be fixed by including the correct headers in +// `utils/enumerate.h`. +#include + +#include "utils/enumerate.h" + +#include + + + +TEST_CASE("reverse", "[Neuron]") { + std::vector x{1.0, 2.0, 3.0}; + + // test/unit_tests/utils/enumerate.cpp:15:26: error: cannot bind non-const + // lvalue reference of type ‘double&’ to an rvalue of type ‘double’ + // 15 | for(auto& i : reverse(x)) { + // | ^ + + // for(auto& i : reverse(x)) { + // i *= -1.0; + // } + +} + +TEST_CASE("reverse; no-copy", "[Neuron]") { + std::vector x{1.0, 2.0, 3.0}; + + auto reverse_iterable = reverse(x); + + for(auto& xx : x) { + xx *= -1.0; + } + + size_t i = 0; + for(const auto& xx : reverse_iterable) { + REQUIRE(xx < 0.0); + } +}