NEURON
check_constructors.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
9 
10 #include <catch2/catch_test_macros.hpp>
11 #include <array>
12 
13 using namespace coreneuron;
14 
15 TEST_CASE("interleave_info_test", "[interleave_info]") {
16  const size_t nwarp = 4;
17  const size_t nstride = 6;
18 
19  InterleaveInfo info1;
20 
21  std::array<int, 10> data1 = {11, 37, 45, 2, 18, 37, 7, 39, 66, 33};
22  std::array<size_t, 9> data2 = {111, 137, 245, 12, 118, 237, 199, 278, 458};
23 
24  info1.nwarp = nwarp;
25  info1.nstride = nstride;
26 
27  // to avoid same values, different sub-array is used to initialize different members
28  copy_align_array(info1.stridedispl, data1.data(), nwarp + 1);
29  copy_align_array(info1.stride, data1.data() + 1, nstride);
30  copy_align_array(info1.firstnode, data1.data() + 1, nwarp + 1);
31  copy_align_array(info1.lastnode, data1.data() + 1, nwarp + 1);
32 
33  // check if copy_array works
34  REQUIRE(info1.firstnode != info1.lastnode);
35  REQUIRE(std::equal(
36  info1.firstnode, info1.firstnode + nwarp + 1, info1.lastnode, info1.lastnode + nwarp + 1));
37 
38  copy_align_array(info1.cellsize, data1.data() + 4, nwarp);
39  copy_array(info1.nnode, data2.data(), nwarp);
40  copy_array(info1.ncycle, data2.data() + 1, nwarp);
41  copy_array(info1.idle, data2.data() + 2, nwarp);
42  copy_array(info1.cache_access, data2.data() + 3, nwarp);
43  copy_array(info1.child_race, data2.data() + 4, nwarp);
44 
45  // copy constructor
46  InterleaveInfo info2(info1);
47 
48  // assignment operator
49  InterleaveInfo info3;
50  info3 = info1;
51 
52  std::vector<InterleaveInfo*> infos;
53 
54  infos.push_back(&info2);
55  infos.push_back(&info3);
56 
57  // test few members
58  for (size_t i = 0; i < infos.size(); i++) {
59  REQUIRE(info1.nwarp == infos[i]->nwarp);
60  REQUIRE(info1.nstride == infos[i]->nstride);
61 
62  REQUIRE(
63  std::equal(info1.stridedispl, info1.stridedispl + nwarp + 1, infos[i]->stridedispl));
64  REQUIRE(std::equal(info1.stride, info1.stride + nstride, infos[i]->stride));
65  REQUIRE(std::equal(info1.cellsize, info1.cellsize + nwarp, infos[i]->cellsize));
66  REQUIRE(std::equal(info1.child_race, info1.child_race + nwarp, infos[i]->child_race));
67  }
68 }
TEST_CASE("interleave_info_test", "[interleave_info]")
#define i
Definition: md1redef.h:19
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
int nstride
Definition: cellorder.cpp:789
void copy_array(T *&dest, T *src, size_t n)
Definition: cellorder.hpp:129
void copy_align_array(T *&dest, T *src, size_t n)
Definition: cellorder.hpp:136
static int equal(const char *c1, const char *c2)
Definition: units.cpp:776