test_state_map.cpp
Go to the documentation of this file.
1 
3 
4 // gtest
5 #include <gtest/gtest.h>
6 
7 // Eigen
8 #include <eigen3/Eigen/Eigen>
9 
11 
12 using namespace std;
13 using namespace Eigen;
14 
15 namespace tuw
16 {
17 TEST(TestStateMap, CopyAssignmentOperatorArray)
18 {
19  using NestedArrayLvl0 = StateMapArray<double, double, 4>;
20  using NestedArrayLvl1 = StateMapArray<double, NestedArrayLvl0, 6>;
21 
22  NestedArrayLvl1 nState0, nState1;
23 
24  for (int i = 0; i < nState0.data().size(); ++i)
25  {
26  nState0.data()(i) = i + 1;
27  }
28  nState1 = nState0;
29  for (int i = 0; i < nState1.data().size(); ++i)
30  {
31  nState1.data()(i) = 0;
32  }
33  for (int i = 0; i < nState0.data().size(); ++i)
34  {
35  EXPECT_EQ(i + 1, nState0.data()(i));
36  }
37 
38  for (int i = 0; i < nState0.data().size(); ++i)
39  {
40  nState0.data()(i) = i + 1;
41  }
42  nState1.sub(0) = nState0.sub(0);
43  for (int i = 0; i < nState1.sub(0).data().size(); ++i)
44  {
45  nState1.sub(0).data()(i) = 0;
46  }
47  for (int i = 0; i < nState0.sub(0).data().size(); ++i)
48  {
49  EXPECT_EQ(i + 1, nState0.sub(0).data()(i));
50  }
51 
52  try
53  {
54  nState1 = NestedArrayLvl1(nState0);
55  FAIL() << "Expected std::runtime_error";
56  }
57  catch (std::runtime_error const &err)
58  {
59  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
60  }
61  catch (...)
62  {
63  FAIL() << "Expected std::runtime_error";
64  }
65 
66  try
67  {
68  nState1.sub(0) = NestedArrayLvl0(nState0.sub(0));
69  FAIL() << "Expected std::runtime_error";
70  }
71  catch (std::runtime_error const &err)
72  {
73  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
74  }
75  catch (...)
76  {
77  FAIL() << "Expected std::runtime_error";
78  }
79 
80  EXPECT_EQ(24, nState1.data().size());
81  for (int i = 0; i < nState1.data().size(); ++i)
82  {
83  EXPECT_EQ(0, nState1.data()(i));
84  }
85 }
86 TEST(TestStateMap, CopyAssignmentOperatorVector)
87 {
88  using NestedVectorLvl0 = StateMapVector<double, double>;
89  using NestedVectorLvl1 = StateMapVector<double, NestedVectorLvl0>;
90 
91  NestedVectorLvl1 nState0, nState1;
92  nState0.subResize(2);
93  nState0.sub(0).subResize(2);
94  for (int i = 0; i < nState0.data().size(); ++i)
95  {
96  nState0.data()(i) = i + 1;
97  }
98 
99  nState1 = nState0;
100  for (int i = 0; i < nState1.data().size(); ++i)
101  {
102  nState1.data()(i) = 0;
103  }
104  for (int i = 0; i < nState0.data().size(); ++i)
105  {
106  EXPECT_EQ(i + 1, nState0.data()(i));
107  }
108 
109  nState1.subResize(5);
110 
111  nState1 = nState0;
112  for (int i = 0; i < nState1.data().size(); ++i)
113  {
114  nState1.data()(i) = 0;
115  }
116  for (int i = 0; i < nState0.data().size(); ++i)
117  {
118  EXPECT_EQ(i + 1, nState0.data()(i));
119  }
120 
121  nState1.sub(0).subResize(7);
122 
123  nState1 = nState0;
124  for (int i = 0; i < nState1.data().size(); ++i)
125  {
126  nState1.data()(i) = 0;
127  }
128  for (int i = 0; i < nState0.data().size(); ++i)
129  {
130  EXPECT_EQ(i + 1, nState0.data()(i));
131  }
132 
133  nState1 = nState0;
134  for (int i = 0; i < nState1.data().size(); ++i)
135  {
136  nState1.data()(i) = 0;
137  }
138  for (int i = 0; i < nState0.data().size(); ++i)
139  {
140  EXPECT_EQ(i + 1, nState0.data()(i));
141  }
142 
143  for (int i = 0; i < nState0.data().size(); ++i)
144  {
145  nState0.data()(i) = i + 1;
146  }
147 
148  nState1.sub(0) = nState0.sub(0);
149  for (int i = 0; i < nState1.data().size(); ++i)
150  {
151  nState1.data()(i) = 0;
152  }
153  for (int i = 0; i < nState0.data().size(); ++i)
154  {
155  EXPECT_EQ(i + 1, nState0.data()(i));
156  }
157 
158  try
159  {
160  nState1 = NestedVectorLvl1(nState0);
161  FAIL() << "Expected std::runtime_error";
162  }
163  catch (std::runtime_error const &err)
164  {
165  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
166  }
167  catch (...)
168  {
169  FAIL() << "Expected std::runtime_error";
170  }
171 
172  try
173  {
174  nState1.sub(0) = NestedVectorLvl0(nState0.sub(0));
175  FAIL() << "Expected std::runtime_error";
176  }
177  catch (std::runtime_error const &err)
178  {
179  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
180  }
181  catch (...)
182  {
183  FAIL() << "Expected std::runtime_error";
184  }
185 
186  EXPECT_EQ(2, nState1.data().size());
187  for (int i = 0; i < nState1.data().size(); ++i)
188  {
189  EXPECT_EQ(0, nState1.data()(i));
190  }
191 }
192 TEST(TestStateMap, CopyAssignmentOperatorTuple)
193 {
194  using NestedVectorLvl0 = StateMapVector<double, double>;
195  using NestedArrayLvl0 = StateMapArray<double, double, 4>;
198 
199  NestedTupleLvl2 nState0, nState1;
200  nState0.sub<0>().sub<1>().subResize(2);
201  for (int i = 0; i < nState0.data().size(); ++i)
202  {
203  nState0.data()(i) = i + 1;
204  }
205 
206  nState1 = nState0;
207  for (int i = 0; i < nState1.data().size(); ++i)
208  {
209  nState1.data()(i) = 0;
210  }
211  for (int i = 0; i < nState0.data().size(); ++i)
212  {
213  EXPECT_EQ(i + 1, nState0.data()(i));
214  }
215 
216  nState1.sub<0>().sub<1>().subResize(7);
217 
218  nState1 = nState0;
219  for (int i = 0; i < nState1.data().size(); ++i)
220  {
221  nState1.data()(i) = 0;
222  }
223  for (int i = 0; i < nState0.data().size(); ++i)
224  {
225  EXPECT_EQ(i + 1, nState0.data()(i));
226  }
227 
228  for (int i = 0; i < nState0.data().size(); ++i)
229  {
230  nState0.data()(i) = i + 1;
231  }
232  nState1.sub<0>() = nState0.sub<0>();
233  for (int i = 0; i < nState1.sub<0>().data().size(); ++i)
234  {
235  nState1.sub<0>().data()(i) = 0;
236  }
237  for (int i = 0; i < nState0.sub<0>().data().size(); ++i)
238  {
239  EXPECT_EQ(i + 1, nState0.sub<0>().data()(i));
240  }
241 
242  for (int i = 0; i < nState0.data().size(); ++i)
243  {
244  nState0.data()(i) = i + 1;
245  }
246  nState1.sub<0>().sub<0>() = nState0.sub<0>().sub<0>();
247  for (int i = 0; i < nState1.sub<0>().sub<0>().data().size(); ++i)
248  {
249  nState1.sub<0>().sub<0>().data()(i) = 0;
250  }
251  for (int i = 0; i < nState0.sub<0>().sub<0>().data().size(); ++i)
252  {
253  EXPECT_EQ(i + 1, nState0.sub<0>().sub<0>().data()(i));
254  }
255 
256  try
257  {
258  nState1 = NestedTupleLvl2(nState0);
259  FAIL() << "Expected std::runtime_error";
260  }
261  catch (std::runtime_error const &err)
262  {
263  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
264  }
265  catch (...)
266  {
267  FAIL() << "Expected std::runtime_error";
268  }
269 
270  try
271  {
272  nState1.sub<0>() = NestedTupleLvl1(nState0.sub<0>());
273  FAIL() << "Expected std::runtime_error";
274  }
275  catch (std::runtime_error const &err)
276  {
277  EXPECT_EQ(std::string("Copy-constructor not allowed"), err.what());
278  }
279  catch (...)
280  {
281  FAIL() << "Expected std::runtime_error";
282  }
283 
284  EXPECT_EQ(10, nState1.data().size());
285  for (int i = 0; i < nState1.data().size(); ++i)
286  {
287  EXPECT_EQ(0, nState1.data()(i));
288  }
289 }
290 
291 class Bla : public StateMapArray<double, double, 3>
292 {
293 public:
294  using StateMapArray::StateMapArray;
295  void asd()
296  {
297  }
298 };
299 
300 TEST(TestStateMap, ExtendedClassInStateMap)
301 {
302  using NestedExtClass = StateMapVector<double, Bla>;
303  NestedExtClass test;
304  test.subResize(1);
305  test.sub(0).asd();
306 }
307 
308 TEST(TestStateMap, NestedArrayVectorOneLvl)
309 {
310  constexpr const size_t sizeLvl0 = 4;
311  using NestedArrayLvl0 = StateMapArray<double, double, sizeLvl0>;
312  using NestedVectorLvl0 = StateMapVector<double, double>;
313 
314  NestedArrayLvl0 nArrLvl0;
315  NestedVectorLvl0 nVecLvl0;
316 }
317 
318 TEST(TestStateMap, NestedArraysCompileTimeSize)
319 {
320  constexpr const size_t sizeLvl0 = 4;
321  constexpr const size_t sizeLvl1 = 3;
322  using NestedLvl0 = StateMapArray<double, double, sizeLvl0>;
324 
325  NestedLvl0 nArrLvl0;
326  EXPECT_EQ(sizeLvl0, nArrLvl0.MapSize);
327  NestedLvl1 nArrLvl1;
328  EXPECT_EQ(sizeLvl1 * sizeLvl0, nArrLvl1.MapSize);
329 }
330 
331 TEST(TestStateMap, NestedVectorsCompileTimeSize)
332 {
333  using NestedLvl0 = StateMapVector<double, double>;
334  using NestedLvl1 = StateMapVector<double, NestedLvl0>;
335 
336  NestedLvl0 nLvl0;
337  NestedLvl1 nLvl1;
338  EXPECT_EQ(Eigen::Dynamic, nLvl0.MapSize);
339  EXPECT_EQ(Eigen::Dynamic, nLvl1.MapSize);
340 }
341 
342 TEST(TestStateMap, NestedArraysVectorsCompileTimeSize)
343 {
344  using NestedVector = StateMapVector<double, double>;
345  using NestedArraySz4 = StateMapArray<double, double, 4>;
346  using NestedArray6Vector = StateMapArray<double, NestedVector, 6>;
347  using NestedVectorArray4 = StateMapVector<double, NestedArraySz4>;
348 
349  NestedArray6Vector nA6V;
350  EXPECT_EQ(Eigen::Dynamic, nA6V.MapSize);
351  EXPECT_EQ(Eigen::Dynamic, nA6V.sub(0).MapSize);
352  NestedVectorArray4 nVA5;
353  EXPECT_EQ(Eigen::Dynamic, nVA5.MapSize);
354  nVA5.subResize(5);
355  EXPECT_EQ(Eigen::Dynamic, nVA5.MapSize);
356  EXPECT_EQ(4, nVA5.sub(1).MapSize);
357 }
358 
359 TEST(TestStateMap, NestedTupleCompileTimeSize)
360 {
361  using NestedVector = StateMapVector<double, double>;
362  using NestedArraySz4 = StateMapArray<double, double, 4>;
363  using NestedArraySz6ArraySz4 = StateMapArray<double, NestedArraySz4, 6>;
364  using NestedArray6Vector = StateMapArray<double, NestedVector, 6>;
365  using NestedArray6Array6Vector = StateMapArray<double, NestedArray6Vector, 6>;
366  using NestedVectorArray4 = StateMapVector<double, NestedArraySz4>;
369  using NestedTupleDynInLvl2 =
371 
372  NestedTupleConst nConst;
373  EXPECT_EQ(24 + 4 + 24, nConst.MapSize);
374  EXPECT_EQ(24, nConst.sub<0>().MapSize);
375  EXPECT_EQ(4, nConst.sub<1>().MapSize);
376  EXPECT_EQ(24, nConst.sub<2>().MapSize);
377  EXPECT_EQ(4, nConst.sub<0>().sub(0).MapSize);
378  EXPECT_EQ(4, nConst.sub<2>().sub(0).MapSize);
379 
380  NestedTupleDynInLvl1 nDynLvl1;
381  nDynLvl1.sub<2>().subResize(2);
382  EXPECT_EQ(Eigen::Dynamic, nDynLvl1.MapSize);
383  EXPECT_EQ(24 + 4 + 24, nDynLvl1.sub<0>().MapSize);
384  EXPECT_EQ(Eigen::Dynamic, nDynLvl1.sub<1>().MapSize);
385  EXPECT_EQ(Eigen::Dynamic, nDynLvl1.sub<2>().MapSize);
386  EXPECT_EQ(4, nDynLvl1.sub<2>().sub(0).MapSize);
387 
388  NestedArray6Array6Vector nDynArArVec;
389  nDynArArVec.sub(0).sub(0).subResize(2);
390  EXPECT_EQ(Eigen::Dynamic, nDynArArVec.MapSize);
391  EXPECT_EQ(Eigen::Dynamic, nDynArArVec.sub(0).MapSize);
392  EXPECT_EQ(Eigen::Dynamic, nDynArArVec.sub(0).sub(0).MapSize);
393 
394  NestedTupleDynInLvl2 nDynLvl2;
395  nDynLvl2.sub<1>().sub(0).sub(0).subResize(2);
396  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.MapSize);
397  EXPECT_EQ(24 + 4 + 24, nDynLvl2.sub<0>().MapSize);
398  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<1>().MapSize);
399  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<2>().MapSize);
400  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<1>().sub(0).MapSize);
401  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<1>().sub(0).sub(0).MapSize);
402  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<2>().sub(0).MapSize);
403  EXPECT_EQ(Eigen::Dynamic, nDynLvl2.sub<2>().sub(0).sub(0).MapSize);
404 }
405 
406 TEST(TestStateMap, NestedStateResize)
407 {
408  using NestedVector = StateMapVector<double, double>;
409  using NestedArraySz4 = StateMapArray<double, double, 4>;
410  using NestedArraySz6 = StateMapArray<double, double, 6>;
411  using NestedVectorArray6 = StateMapVector<double, NestedArraySz6>;
412  using NestedArray6Vector = StateMapArray<double, NestedVector, 6>;
413  using NestedArray6Array6Vector = StateMapArray<double, NestedArray6Vector, 6>;
414  using NestedVectorArray4 = StateMapVector<double, NestedArraySz4>;
417 
418  NestedTupleLvl2 nState;
419  EXPECT_EQ(4, nState.data().size());
420  for (int i = 0; i < nState.data().size(); ++i)
421  {
422  nState.data()(i) = 1;
423  }
424  // cout<<nState.data().transpose()<<endl;
425  nState.sub<2>().subResize(2);
426  EXPECT_EQ(4 + 2 * 4, nState.data().size());
427  // cout<<nState.data().transpose()<<endl;
428  for (int i = 0; i < nState.sub<2>().sub(0).data().size(); ++i)
429  {
430  nState.sub<2>().sub(0).data()(i) = 2;
431  }
432  for (int i = 0; i < nState.sub<2>().sub(1).data().size(); ++i)
433  {
434  nState.sub<2>().sub(1).data()(i) = 3;
435  }
436  // cout<<nState.data().transpose()<<endl;
437  nState.sub<1>().sub(0).sub(0).subResize(1);
438  for (int i = 0; i < nState.sub<1>().sub(0).sub(0).data().size(); ++i)
439  {
440  nState.sub<1>().sub(0).sub(0).data()(i) = 4;
441  }
442  EXPECT_EQ(4 + 2 * 4 + 1, nState.data().size());
443  nState.sub<1>().sub(0).sub(1).subResize(2);
444  for (int i = 0; i < nState.sub<1>().sub(0).sub(1).data().size(); ++i)
445  {
446  nState.sub<1>().sub(0).sub(1).data()(i) = 5;
447  }
448  EXPECT_EQ(4 + 2 * 4 + 1 + 2, nState.data().size());
449  nState.sub<1>().sub(1).sub(0).subResize(3);
450  for (int i = 0; i < nState.sub<1>().sub(1).sub(0).data().size(); ++i)
451  {
452  nState.sub<1>().sub(1).sub(0).data()(i) = 6;
453  }
454  EXPECT_EQ(4 + 2 * 4 + 1 + 2 + 3, nState.data().size());
455  // cout<<nState.data().transpose()<<endl;
456  nState.sub<0>().sub<0>().subResize(3);
457  for (int i = 0; i < nState.sub<0>().sub<0>().data().size(); ++i)
458  {
459  nState.sub<0>().sub<0>().data()(i) = 7;
460  }
461  EXPECT_EQ(4 + 2 * 4 + 1 + 2 + 3 + 3, nState.data().size());
462  nState.sub<0>().sub<2>().subResize(2);
463  for (int i = 0; i < nState.sub<0>().sub<2>().data().size(); ++i)
464  {
465  nState.sub<0>().sub<2>().data()(i) = 8;
466  }
467  EXPECT_EQ(4 + 2 * 4 + 1 + 2 + 3 + 3 + 2 * 6, nState.data().size());
468  // cout<<nState.data().transpose()<<endl;
469  std::array<double, 4 + 2 * 4 + 1 + 2 + 3 + 3 + 2 * 6> numRes = { 7, 7, 7, 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
470  8, 8, 4, 5, 5, 6, 6, 6, 2, 2, 2, 2, 3, 3, 3, 3 };
471  for (size_t i = 0; i < numRes.size(); ++i)
472  {
473  EXPECT_EQ(numRes[i], nState.data()(i));
474  }
475 
476  nState.sub<0>().sub<0>().subResize(1);
477  nState.sub<2>().subResize(1);
478  std::array<double, 4 + 1 * 4 + 1 + 2 + 3 + 1 + 2 * 6> numRes2 = { 7, 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8,
479  8, 8, 8, 4, 5, 5, 6, 6, 6, 2, 2, 2, 2 };
480  for (size_t i = 0; i < numRes2.size(); ++i)
481  {
482  EXPECT_EQ(numRes2[i], nState.data()(i));
483  }
484 
485  nState.sub<0>().sub<0>().subResize(0);
486  nState.sub<2>().subResize(0);
487  std::array<double, 4 + 0 * 4 + 1 + 2 + 3 + 0 + 2 * 6> numRes3 = { 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8,
488  8, 8, 8, 8, 8, 4, 5, 5, 6, 6, 6 };
489  for (size_t i = 0; i < numRes3.size(); ++i)
490  {
491  EXPECT_EQ(numRes3[i], nState.data()(i));
492  }
493 }
494 
495 TEST(TestStateMap, ResizeWithEmptyVectors)
496 {
497  constexpr const size_t sizeLvl0 = 4;
498  using NestedVectorBase = StateMapVector<double, double>;
500  using NestedVector = StateMapVector<double, NestedArray>;
501 
502  NestedVector nState;
503  NestedArray nArr;
504  nArr.sub(0).subResize(2);
505  nState.subResize(2);
506  // cout<<nState.data().transpose()<<endl;
507  nState.sub(0).sub(0).subResize(1);
508  // cout<<nState.data().transpose()<<endl;
509  for (int i = 0; i < nState.data().size(); ++i)
510  {
511  nState.data()(i) = 1;
512  }
513  // cout<<nState.data().transpose()<<endl;
514  nState.sub(0).sub(0).subResize(3);
515  std::array<double, 3> numRes0 = { 1, 0, 0 };
516  for (int i = 0; i < nState.data().size(); ++i)
517  {
518  EXPECT_EQ(numRes0[i], nState.data()(i));
519  }
520 
521  // cout<<nState.data().transpose()<<endl;
522  nState.subResize(2);
523 
524  for (int i = 0; i < nState.data().size(); ++i)
525  {
526  EXPECT_EQ(numRes0[i], nState.data()(i));
527  }
528 }
529 
530 TEST(TestStateMap, NestedArraysDataBuffer)
531 {
532  constexpr const size_t sizeLvl0 = 4;
533  constexpr const size_t sizeLvl1 = 3;
534  using NestedLvl0 = StateMapArray<double, double, sizeLvl0>;
536 
537  Eigen::Vector4d inc4(1., 2., 3., 4.);
538  Eigen::Vector3d dec3(9., 8., 7.);
539  NestedLvl0 nArrLvl0;
540  NestedLvl1 nArrLvl1;
541  nArrLvl1.data().block(0, 0, 3, 1) = dec3;
542  nArrLvl1.data().block(3, 0, 3, 1) = dec3;
543  nArrLvl1.data().block(6, 0, 3, 1) = dec3;
544  nArrLvl1.data().block(9, 0, 3, 1) = dec3;
545  for (int i = 0; i < nArrLvl1.data().size(); ++i)
546  {
547  EXPECT_EQ(9 - i % 3, nArrLvl1.data()(i));
548  }
549  nArrLvl1.data().block(7, 0, 4, 1) = inc4;
550  for (int i = 7; i < 7 + 4; ++i)
551  {
552  EXPECT_EQ(i - 7 + 1, nArrLvl1.data()(i));
553  }
554  nArrLvl1.sub(0).data() = inc4;
555  nArrLvl1.sub(2).data() = inc4;
556  for (int i = 0; i < nArrLvl1.sub(0).data().rows(); ++i)
557  {
558  EXPECT_EQ(i + 1, nArrLvl1.data()(i));
559  }
560  for (int i = 2 * (int)sizeLvl0; i < 2 * (int)sizeLvl0 + nArrLvl1.sub(3).data().rows(); ++i)
561  {
562  EXPECT_EQ(i + 1 - 2 * sizeLvl0, nArrLvl1.data()(i));
563  }
564 }
565 
566 TEST(TestStateMap, VirtualBase)
567 {
568  using NestedArray4 = StateMapArray<double, double, 6>;
569  using NestedVectorArray6 = StateMapVector<double, NestedArray4>;
570  using NestedArray4VectorArray6 = StateMapArray<double, NestedVectorArray6, 4>;
571 
572  std::shared_ptr<StateMapBaseVirt<double>> nStateBaseVirt = std::shared_ptr<NestedArray4VectorArray6>(new NestedArray4VectorArray6);
573 
574  nStateBaseVirt->sub(0).subResize(2);
575  for (int i = 0; i < nStateBaseVirt->data().size(); ++i)
576  {
577  nStateBaseVirt->data()(i) = i;
578  }
579  // cout<<nStateBaseVirt->data().transpose()<<endl;
580  for (int i = 0; i < nStateBaseVirt->data().size(); ++i)
581  {
582  EXPECT_EQ(i, nStateBaseVirt->data()(i));
583  }
584 
585  try
586  {
587  nStateBaseVirt->subResize(2);
588  FAIL() << "Expected std::runtime_error";
589  }
590  catch (std::runtime_error const &err)
591  {
592  EXPECT_EQ(std::string("Cannot resize an array"), err.what());
593  }
594  catch (...)
595  {
596  FAIL() << "Expected std::runtime_error";
597  }
598 
599  try
600  {
601  nStateBaseVirt->sub(0).sub(0).sub(0);
602  FAIL() << "Expected std::runtime_error";
603  }
604  catch (std::runtime_error const &err)
605  {
606  EXPECT_EQ(std::string("Access of numeric Leaf using virtual \"sub\" function not allowed"), err.what());
607  }
608  catch (...)
609  {
610  FAIL() << "Expected std::runtime_error";
611  }
612 
613  using NestedTupleArray4VectorArray6 = StateMapTuple<double, NestedArray4, NestedVectorArray6>;
614 
615  std::shared_ptr<StateMapBaseVirt<double>> nStateTupBaseVirt = std::shared_ptr<NestedTupleArray4VectorArray6>(new NestedTupleArray4VectorArray6);
616 
617  nStateTupBaseVirt->sub(1).subResize(2);
618  for (int i = 0; i < nStateTupBaseVirt->data().size(); ++i)
619  {
620  nStateTupBaseVirt->data()(i) = i;
621  }
622  try
623  {
624  nStateTupBaseVirt->subResize(2);
625  FAIL() << "Expected std::runtime_error";
626  }
627  catch (std::runtime_error const &err)
628  {
629  EXPECT_EQ(std::string("Cannot resize a tuple"), err.what());
630  }
631  catch (...)
632  {
633  FAIL() << "Expected std::runtime_error";
634  }
635 
636  std::shared_ptr<NestedTupleArray4VectorArray6> nStateTupExt =
637  dynamic_pointer_cast<NestedTupleArray4VectorArray6>(nStateTupBaseVirt);
638  std::shared_ptr<StateMapBaseCRTP<NestedTupleArray4VectorArray6>> nStateTupBaseCRTP = nStateTupExt;
639 
640  for (int i = 0; i < nStateTupBaseVirt->sub(1).data().size(); ++i)
641  {
642  EXPECT_EQ(i + 6, nStateTupBaseVirt->sub(1).data()(i));
643  }
644  for (int i = 0; i < nStateTupExt->sub<1>().data().size(); ++i)
645  {
646  EXPECT_EQ(i + 6, nStateTupExt->sub<1>().data()(i));
647  }
648  for (int i = 0; i < nStateTupBaseCRTP->sub<1>().data().size(); ++i)
649  {
650  EXPECT_EQ(i + 6, nStateTupBaseCRTP->sub<1>().data()(i));
651  }
652 }
653 
654 } // namespace <anonymous>
655 
656 int main(int argc, char **argv)
657 {
658  testing::InitGoogleTest(&argc, argv);
659  srand((int)time(0));
660  return RUN_ALL_TESTS();
661 }
Helper function needed to upgrade c++ 2011.
Definition: utils.h:193
void subResize(const size_t &_size)
LeafType & sub(const size_t &_i)
int main(int argc, char **argv)
TEST(TestStateMap, VirtualBase)


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:22