Skip to content

Commit

Permalink
Add first tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Sep 22, 2023
1 parent 359fc46 commit 7ffed3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions test/unit_tests/utils/enumerate.cpp
Original file line number Diff line number Diff line change
@@ -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 <vector>

#include "utils/enumerate.h"

#include <catch2/catch.hpp>



TEST_CASE("reverse", "[Neuron]") {
std::vector<double> 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<double> 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);
}
}

0 comments on commit 7ffed3d

Please sign in to comment.