astrotypes  0.0
SliceTest.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "../SliceTest.h"
26 
27 #include <vector>
28 #include <cmath>
29 
30 
31 namespace pss {
32 namespace astrotypes {
33 namespace test {
34 
35 
37  : ::testing::Test()
38 {
39 }
40 
42 {
43 }
44 
46 {
47 }
48 
50 {
51 }
52 
53 struct DimensionA {};
54 struct DimensionB {};
55 struct DimensionC {};
56 
57 template<typename T>
58 class TestSliceMixin : public T
59 {
60  public:
61  TestSliceMixin(T const& t) : T(t) {}
62  using T::T;
63 };
64 
65 template<int NDim, typename ValueType=int>
66 struct ParentType {
67  typedef ValueType value_type;
68  typedef int& reference_type;
69  typedef typename std::vector<value_type>::iterator iterator;
70  typedef typename std::vector<value_type>::const_iterator const_iterator;
71 
72  ParentType(std::size_t size)
73  : _vec(std::pow(size, NDim))
74  , _size(size)
75  {
76  unsigned index=0;
77 
78  while(index<_vec.size()) {
79  _vec[index]=index;
80  ++index;
81  }
82  }
83 
84  iterator begin() {
85  return _vec.begin();
86  }
87 
88  const_iterator begin() const {
89  return _vec.begin();
90  }
91 
92  template<typename Dimension>
95  }
96 
97  template<typename Dimension>
100  }
101 
102  std::vector<value_type> _vec;
103  std::size_t _size;
104 };
105 
106 
107 TEST_F(SliceTest, test_single_dimension)
108 {
109  ParentType<1> p(50);
111  // test size
112  ASSERT_EQ(11U, static_cast<std::size_t>(slice.size<DimensionA>()));
113  ASSERT_EQ(0U, static_cast<std::size_t>(slice.size<DimensionB>()));
114  ASSERT_EQ(11U, static_cast<std::size_t>(slice.dimension<DimensionA>()));
115  ASSERT_EQ(0U, static_cast<std::size_t>(slice.dimension<DimensionB>()));
116 
117  // test operator[]
118  for(std::size_t i = 0; i < slice.dimension<DimensionA>(); ++i) {
119  ASSERT_EQ(slice[i], i+ 10U); // check we can read
120  slice[i]=i; // and write
121  }
122 }
123 
124 TEST_F(SliceTest, test_single_dimension_iterators)
125 {
126  ParentType<1> p(50);
128 
129  // test operator[]
130  auto it = slice.begin();
131  typedef typename std::iterator_traits<typename decltype(p)::iterator>::iterator_category expected_iterator_category;
132  static_assert(std::is_same<std::iterator_traits<decltype(it)>::iterator_category, expected_iterator_category>::value,
133  "expecting a vector iterator category");
134  auto const& const_slice = slice;
135  auto it2 = const_slice.begin();
136  static_assert(std::is_same<std::iterator_traits<decltype(it2)>::iterator_category, expected_iterator_category>::value,
137  "expecting a vector iterator category");
138  auto it3 = const_slice.cbegin();
139  static_assert(std::is_same<std::iterator_traits<decltype(it3)>::iterator_category, expected_iterator_category>::value,
140  "expecting a vector iterator category");
141 
142  for(std::size_t i = 0; i < slice.size<DimensionA>(); ++i) {
143  ASSERT_FALSE(it == slice.end()) << "i=" << i << " end=" << *slice.end() << " it=" << *it;
144  ASSERT_FALSE(it2 == slice.end()) << "i=" << i << " end=" << *slice.end() << " it=" << *it2;
145  ASSERT_FALSE(it3 == slice.cend()) << "i=" << i << " end=" << *slice.cend() << " it=" << *it3;
146  ASSERT_EQ(*it, i+ 10U); // check we can read
147  ASSERT_EQ(*it2, i+ 10U); // check we can read
148  ASSERT_EQ(*it3, i+ 10U); // check we can read
149  // check non const iterator can write
150  (*it) += 1;
151  ASSERT_EQ(*it, i+ 11U); // check we can write
152  ++it;
153  ++it2;
154  ++it3;
155  }
156  ASSERT_TRUE(it == slice.end()) << "end=" << *slice.end() << " it=" << *it;
157  ASSERT_TRUE(it2 == slice.end()) << "end=" << *slice.cend() << " it2=" << *it2;
158  ASSERT_TRUE(it3 == slice.cend()) << "end=" << *slice.cend() << " it3=" << *it3;
159 }
160 
161 TEST_F(SliceTest, test_single_dimension_iterators_diff)
162 {
163  ParentType<1> const p(50);
165 
166  auto it = slice.begin();
167  auto it2 = slice.begin();
168  for(unsigned i=0; i < slice.size<DimensionA>(); ++i) {
169  ASSERT_EQ(i, it2 - it) << i;
170  ++it2;
171  }
172 }
173 
174 TEST_F(SliceTest, test_single_dimension_equals)
175 {
176  ParentType<1> const p(50);
177  ParentType<1> p2(50);
180  ASSERT_EQ(slice, slice_2);
181  slice_2[1] = 0;
182  ASSERT_FALSE(slice==slice_2);
183 }
184 
185 TEST_F(SliceTest, test_one_dimensions_slice_copy)
186 {
187  ParentType<1> p(50);
188  const ParentType<1> const_p(50);
191  );
192  Slice<false, ParentType<1>, TestSliceMixin, DimensionA> slice_copy = slice;
193  ASSERT_EQ(&slice_copy.parent(), &slice.parent());
194 
195  Slice<true, ParentType<1>, TestSliceMixin, DimensionA> const_slice(const_p
197  );
198  Slice<true, ParentType<1>, TestSliceMixin, DimensionA> const_slice_copy = const_slice;
199  ASSERT_EQ(&const_slice_copy.parent(), &const_slice.parent());
200 }
201 
202 TEST_F(SliceTest, test_singe_dimension_slice_iterators_copy)
203 {
204  ParentType<1> p(50);
207  );
208  auto it = slice.begin();
209  decltype(it) copy_it = it;
210  ASSERT_TRUE(copy_it == it);
211 
212  auto const_it = slice.cbegin();
213  decltype(const_it) copy_const_it = const_it;
214  ASSERT_TRUE(copy_const_it == const_it);
215 }
216 
217 
218 TEST_F(SliceTest, test_two_dimensions)
219 {
220  ParentType<2> p(50);
224  );
225  Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> const_slice(p
228  );
229  // check parent()
230  ASSERT_EQ(&p, &slice.parent());
231  ASSERT_EQ(&p, &const_slice.parent());
232 
233  // test size
234  ASSERT_EQ(10U, static_cast<std::size_t>(slice.size<DimensionA>()));
235  ASSERT_EQ(3U, static_cast<std::size_t>(slice.size<DimensionB>()));
236  ASSERT_EQ(10U, static_cast<std::size_t>(slice.dimension<DimensionA>()));
237  ASSERT_EQ(3U, static_cast<std::size_t>(slice.dimension<DimensionB>()));
238 
239  // test operator[]
240  ASSERT_EQ(3U, static_cast<std::size_t>(slice[DimensionIndex<DimensionA>(0)].size<DimensionB>()));
241  ASSERT_EQ(10U, static_cast<std::size_t>(slice[DimensionIndex<DimensionB>(0)].size<DimensionA>()));
242  ASSERT_EQ(1U, static_cast<std::size_t>(slice[DimensionIndex<DimensionB>(0)].size<DimensionB>()));
243 
244  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
245  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
246  ASSERT_EQ(slice[i][j], (static_cast<std::size_t>(i) + 10U) * static_cast<std::size_t>(p.size<DimensionB>()) + static_cast<std::size_t>(j) + 20U) << "i=" << i << " j=" << j; // check we can read
247  ASSERT_EQ(const_slice[i][j], (static_cast<std::size_t>(i) + 10U) * static_cast<std::size_t>(p.size<DimensionB>()) + static_cast<std::size_t>(j) + 20U) << "i=" << i << " j=" << j; // check we can read
248  ASSERT_EQ(slice[j][i], slice[i][j]) << "i=" << i << " j=" << j; // check we can read
249  ASSERT_EQ(const_slice[j][i], slice[i][j]) << "i=" << i << " j=" << j; // check we can read
250  }
251  }
252 
253 }
254 
255 TEST_F(SliceTest, test_two_dimensions_contructor_out_of_order_dims)
256 {
257  ParentType<2> p(50);
261  );
262  Slice<false, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> slice_b(p
265  );
266 
267  ASSERT_EQ(10U, static_cast<std::size_t>(slice_a.size<DimensionA>()));
268  ASSERT_EQ(3U, static_cast<std::size_t>(slice_a.size<DimensionB>()));
269  ASSERT_EQ(10U, static_cast<std::size_t>(slice_b.size<DimensionA>()));
270  ASSERT_EQ(3U, static_cast<std::size_t>(slice_b.size<DimensionB>()));
271 
272  Slice<false, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> slice_c(p
274  );
275  ASSERT_EQ(50U, static_cast<std::size_t>(slice_c.size<DimensionA>()));
276  ASSERT_EQ(3U, static_cast<std::size_t>(slice_c.size<DimensionB>()));
277 
278  Slice<false, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> slice_d(p
280  );
281 
282  ASSERT_EQ(10U, static_cast<std::size_t>(slice_d.size<DimensionA>()));
283  ASSERT_EQ(50U, static_cast<std::size_t>(slice_d.size<DimensionB>()));
284 }
285 
286 TEST_F(SliceTest, test_two_dimensions_slice_iterators)
287 {
288  ParentType<2> p(50);
292  );
293  auto it = slice.begin();
294  auto const_it = slice.cbegin();
295  ASSERT_EQ(&*it, &*p.begin() + 10 * p.size<DimensionB>() + 20);
296  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
297  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
298  ASSERT_EQ(slice[i][j], *it);
299  ASSERT_EQ(slice[i][j], *const_it);
300  ++it;
301  ++const_it;
302  }
303  }
304 }
305 
306 TEST_F(SliceTest, test_two_dimensions_slice_copy)
307 {
308  ParentType<2> p(50);
309  const ParentType<2> const_p(50);
313  );
314  Slice<false, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> slice_copy = slice;
315  ASSERT_EQ(&slice_copy.parent(), &slice.parent());
316 
317  Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> const_slice(const_p
320  );
321  Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> const_slice_copy = const_slice;
322  ASSERT_EQ(&const_slice_copy.parent(), &const_slice.parent());
323 }
324 
325 
326 TEST_F(SliceTest, test_two_dimensions_slice_iterators_copy)
327 {
328  ParentType<2> p(50);
332  );
333  auto it = slice.begin();
334  decltype(it) copy_it = it;
335  ASSERT_TRUE(it == copy_it);
336 
337  auto const_it = slice.cbegin();
338  decltype(const_it) copy_const_it = const_it;
339  ASSERT_TRUE(const_it == copy_const_it);
340 }
341 
342 TEST_F(SliceTest, test_two_dimensions_slice_iterators_overlay)
343 {
344  ParentType<2> p(50);
345  ParentType<2> overlay_p(50);
349  );
350 
351  auto it = slice.begin();
352  auto const_it = slice.cbegin();
353  ASSERT_EQ(&*it(overlay_p), &*overlay_p.begin() + 10 * overlay_p.size<DimensionB>() + 20);
354  ASSERT_EQ(&*const_it(p), &*p.begin() + 10 * p.size<DimensionB>() + 20);
355  ASSERT_EQ(&*const_it(overlay_p), &*overlay_p.begin() + 10 * p.size<DimensionB>() + 20) << "overlay begin=" << &*overlay_p.begin();
356 
357  // if of a different type
358  ParentType<2, double> overlay_different_type(50);
359  ASSERT_EQ(&*const_it(overlay_different_type), &*overlay_different_type.begin() + 10 * p.size<DimensionB>() + 20);
360 }
361 
362 TEST_F(SliceTest, test_two_dimensions_slice_of_slice)
363 {
364  ParentType<2> p(50);
368  );
369  {
370  // sub slice in DimensionA
372  auto it = slice.begin();
373  auto const_it = slice.cbegin();
374  ASSERT_EQ(&*it, &*p.begin() + 12 * p.size<DimensionB>() + 20);
375  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
376  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
377  ASSERT_EQ(slice[i][j], *it) << "i=" << i << " j=" << j;
378  ASSERT_EQ(slice[i][j], *const_it) << "i=" << i << " j=" << j;
379  ++it;
380  ++const_it;
381  }
382  }
383  }
384  {
385  // sub slice in DimensionA and Dimesnion B
388  auto it = slice.begin();
389  auto const_it = slice.cbegin();
390  ASSERT_EQ(&*it, &*p.begin() + 12 * p.size<DimensionB>() + 21);
391  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
392  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
393  ASSERT_EQ(slice[i][j], *it);
394  ASSERT_EQ(slice[i][j], *const_it);
395  ++it;
396  ++const_it;
397  }
398  }
399  }
400  {
401  // sub slice in DimensionB only
403  auto it = slice.begin();
404  auto const_it = slice.cbegin();
405  ASSERT_EQ(&*it, &*p.begin() + 10 * p.size<DimensionB>() + 21);
406  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
407  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
408  ASSERT_EQ(slice[i][j], *it);
409  ASSERT_EQ(slice[i][j], *const_it);
410  ++it;
411  ++const_it;
412  }
413  }
414  }
415 }
416 
417 TEST_F(SliceTest, test_two_dimensions_iterators_diff)
418 {
419  ParentType<2> p(50);
423  );
424  auto it = slice.begin();
425  auto it2 = slice.begin();
426  // check inner loop
427  std::size_t count = 0;
428  while(it2 != slice.end()) {
429  ASSERT_EQ(count, it2 - it) << count;
430  ++count;
431  ++it2;
432  }
433 }
434 
435 TEST_F(SliceTest, test_three_dimensions)
436 {
437  ParentType<3> p(50);
442  );
443  // test size
444  ASSERT_EQ(10U, static_cast<std::size_t>(slice.size<DimensionA>()));
445  ASSERT_EQ(3U, static_cast<std::size_t>(slice.size<DimensionB>()));
446  ASSERT_EQ(5U, static_cast<std::size_t>(slice.size<DimensionC>()));
447 
448  // test operator[]
449  ASSERT_EQ(3U, static_cast<std::size_t>(slice[DimensionIndex<DimensionA>(0)].size<DimensionB>()));
450  ASSERT_EQ(5U, static_cast<std::size_t>(slice[DimensionIndex<DimensionA>(0)].size<DimensionC>()));
451  ASSERT_EQ(5U, static_cast<std::size_t>(slice[DimensionIndex<DimensionA>(0)][DimensionIndex<DimensionB>(0)].size<DimensionC>()));
452 
453  for(DimensionIndex<DimensionA> i(0); i < slice.size<DimensionA>(); ++i) {
454  for(DimensionIndex<DimensionB> j(0); j < slice.size<DimensionB>(); ++j) {
455  for(DimensionIndex<DimensionC> k(0); k < slice.size<DimensionC>(); ++k) {
456  ASSERT_EQ(slice[i][j][k],
457  ((std::size_t)i + 1U) * static_cast<std::size_t>(p.size<DimensionB>()) * static_cast<std::size_t>(p.size<DimensionC>())
458  + ((std::size_t)j + 20U) * static_cast<std::size_t>(p.size<DimensionC>())
459  + (std::size_t)k + 2U) << "i=" << i << " j=" << j << " k=" << k; // check we can read
460  ASSERT_EQ(slice[i][j][k], slice[i][k][j]);
461 // ASSERT_EQ(slice[i][j][k], slice[j][i][k]) << "i=" << i << " j=" << j << " k=" << k;
462 // ASSERT_EQ(slice[i][j][k], slice[j][k][i]) << "i=" << i << " j=" << j << " k=" << k;
463 // ASSERT_EQ(slice[i][j][k], slice[k][j][i]) << "i=" << i << " j=" << j << " k=" << k;
464 // ASSERT_EQ(slice[i][j][k], slice[k][i][j]) << "i=" << i << " j=" << j << " k=" << k;
465  }
466  }
467  }
468 }
469 
470 TEST_F(SliceTest, test_three_dimensions_same_dim_sub_slice)
471 {
472  ParentType<3> p(50);
477  );
478  // cut a sub slice (should be of the same type - hence no auto
479  Slice<false, ParentType<3>, TestSliceMixin, DimensionA, DimensionB, DimensionC> sub_slice =
481 
482  ASSERT_EQ(5U, static_cast<std::size_t>(sub_slice.size<DimensionA>()));
483  ASSERT_EQ(3U, static_cast<std::size_t>(sub_slice.size<DimensionB>()));
484  ASSERT_EQ(5U, static_cast<std::size_t>(sub_slice.size<DimensionC>()));
485 
486  for(DimensionIndex<DimensionA> i(0); i < sub_slice.size<DimensionA>(); ++i) {
487  for(DimensionIndex<DimensionB> j(0); j < sub_slice.size<DimensionB>(); ++j) {
488  for(DimensionIndex<DimensionC> k(0); k < sub_slice.size<DimensionC>(); ++k) {
489  ASSERT_EQ(sub_slice[i][j][k],
490  ((std::size_t)i + 1U + 2U) * static_cast<std::size_t>(p.size<DimensionB>()) * static_cast<std::size_t>(p.size<DimensionC>())
491  + ((std::size_t)j + 20U) * static_cast<std::size_t>(p.size<DimensionC>())
492  + (std::size_t)k + 2U) << "i=" << i << " j=" << j << " k=" << k; // check we can read
493  }
494  }
495  }
496 }
497 
498 TEST_F(SliceTest, test_three_dimensions_slice_iterators)
499 {
500  ParentType<3> p(50);
505  );
506  Slice<false, ParentType<3>, TestSliceMixin, DimensionA, DimensionB, DimensionC> sub_slice =
508 
509  auto it = sub_slice.begin();
510  auto end = sub_slice.end();
511  for(DimensionIndex<DimensionA> i(0); i < sub_slice.size<DimensionA>(); ++i) {
512  for(DimensionIndex<DimensionB> j(0); j < sub_slice.size<DimensionB>(); ++j) {
513  for(DimensionIndex<DimensionC> k(0); k < sub_slice.size<DimensionC>(); ++k) {
514  unsigned val = *it;
515  ASSERT_EQ( val, sub_slice[i][j][k]) << "i=" << i << " j=" << j << " k=" << k; // check we can read
516  ASSERT_FALSE(it == end) << "i=" << i << " j=" << j << " k=" << k << " end=" << *end << " it=" << *it;
517  ++it;
518  }
519  }
520  }
521  ASSERT_TRUE(it == sub_slice.end()) << "end=" << *sub_slice.end() << " it=" << *it;
522 }
523 
524 TEST_F(SliceTest, const_test_three_dimensions_slice_iterators)
525 {
526  ParentType<3> const p(50);
531  );
532  Slice<true, ParentType<3>, TestSliceMixin, DimensionA, DimensionB, DimensionC> sub_slice =
534 
535  auto it = sub_slice.begin();
536  static_assert(std::is_same<std::iterator_traits<decltype(it)>::iterator_category, std::forward_iterator_tag>::value, "expecting a forward iterator");
537  auto it2 = sub_slice.cbegin();
538  static_assert(std::is_same<std::iterator_traits<decltype(it2)>::iterator_category, std::forward_iterator_tag>::value, "expecting a forward iterator");
539  for(DimensionIndex<DimensionA> i(0); i < sub_slice.size<DimensionA>(); ++i) {
540  for(DimensionIndex<DimensionB> j(0); j < sub_slice.size<DimensionB>(); ++j) {
541  for(DimensionIndex<DimensionC> k(0); k < sub_slice.size<DimensionC>(); ++k) {
542  unsigned val = *it;
543  ASSERT_EQ( val, sub_slice[i][j][k]) << "i=" << i << " j=" << j << " k=" << k; // check we can read
544  ASSERT_FALSE(it == sub_slice.end()) << "i=" << i << " j=" << j << " k=" << k << " end=" << *sub_slice.end() << " it=" << *it;
545  ASSERT_FALSE(it2 == sub_slice.cend()) << "i=" << i << " j=" << j << " k=" << k << " end=" << *sub_slice.cend() << " it2=" << *it2;
546  ++it;
547  ++it2;
548  }
549  }
550  }
551  ASSERT_TRUE(it == sub_slice.end()) << "end=" << *sub_slice.end() << " it=" << *it;
552  ASSERT_TRUE(it2 == sub_slice.cend()) << "end=" << *sub_slice.cend() << " it2=" << *it2;
553 }
554 
555 TEST_F(SliceTest, test_three_dimensions_iterators_diff)
556 {
557  ParentType<3> p(50);
562  );
563  auto it = slice.begin();
564  auto it2 = slice.begin();
565  // check inner loop
566  std::size_t count = 0;
567  while(it2 != slice.end()) {
568  ASSERT_EQ(count, it2 - it) << count;
569  ++count;
570  ++it2;
571  }
572 }
573 
574 TEST_F(SliceTest, test_three_dimensions_equals)
575 {
576  ParentType<3> const p(50);
581  );
582  ParentType<3> p2(50);
583  Slice<false, ParentType<3>, TestSliceMixin, DimensionA, DimensionB, DimensionC> slice_2(p2
587  );
588  ASSERT_EQ(slice, slice_2);
589 
590  // dirrent data
594  ASSERT_FALSE(slice==slice_2);
595 
596 }
597 
598 TEST_F(SliceTest, test_has_dimension)
599 {
600  typedef Slice<true, ParentType<1>, TestSliceMixin, DimensionA> TestSlice1d;
601  static_assert(std::is_same<typename has_dimension<TestSlice1d, DimensionA>::type, std::true_type>::value, "expecting true");
602  static_assert(std::is_same<typename has_dimension<TestSlice1d, DimensionB>::type, std::false_type>::value, "expecting false");
603 }
604 
605 TEST_F(SliceTest, test_is_multi_dimension)
606 {
607  typedef Slice<true, ParentType<2>, TestSliceMixin, DimensionA> TestSlice1d;
608  static_assert(std::is_same<typename has_exact_dimensions<TestSlice1d, DimensionA>::type, std::true_type>::value, "expecting true");
609  static_assert(std::is_same<typename has_exact_dimensions<TestSlice1d, DimensionB>::type, std::false_type>::value, "expecting false");
610 
611  typedef Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB> TestSlice2d;
613  static_assert(std::is_same<typename has_exact_dimensions<TestSlice2d, DimensionA, DimensionB>::type, std::true_type>::value, "expecting true");
614  ASSERT_TRUE(r);
615  r = has_exact_dimensions<Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB>, DimensionA, DimensionB>::value;
616  ASSERT_TRUE(r);
617  r = has_exact_dimensions<Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB>, DimensionA>::value;
618  ASSERT_FALSE(r);
619  r = has_exact_dimensions<Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB>, DimensionB>::value;
620  ASSERT_FALSE(r);
621  r = has_exact_dimensions<Slice<true, ParentType<2>, TestSliceMixin, DimensionA, DimensionB>, DimensionB, DimensionA>::value;
622  ASSERT_FALSE(r);
623 }
624 
625 } // namespace test
626 } // namespace astrotypes
627 } // namespace pss
iterator end()
iterator pointing to just after the last element
Definition: Slice.cpp:455
A tagged dimensionIndex variable.
iterator begin()
iterator pointing to the first element in the slice
Definition: Slice.cpp:437
Defines a contiguous range over dimension in index.
Definition: DimensionSpan.h:41
std::vector< value_type > _vec
Definition: SliceTest.cpp:102
std::vector< value_type >::const_iterator const_iterator
Definition: SliceTest.cpp:70
STL namespace.
Representation of a Slice through a Data Array.
Definition: Slice.h:105
std::enable_if< std::is_same< Dim, Dimension >::value, DimensionSize< Dimension > >::type size() const
DimensionSize< Dimension > size() const
Definition: SliceTest.cpp:93
TEST_F(MultiArrayTest, test_single_dimension_size)
std::enable_if< arg_helper< Dimension, Dims...>::value, SliceType >::type slice(DimensionSpan< Dims > const &...spans)
Take a sub-slice from this slice pass a DimensionSpan object for each dimension you wish ...
std::vector< value_type >::iterator iterator
Definition: SliceTest.cpp:69
const_iterator cend() const
Definition: Slice.cpp:467
Parent & parent() const
return refernce to the parent object the Slice is based on
Definition: Slice.cpp:473
return true if the Dimensions provided match exactly those of the structure T (including order) ...
Definition: TypeTraits.h:107
A compile time dimesion tagging of size_t.
Definition: DimensionSize.h:39
const_iterator begin() const
Definition: SliceTest.cpp:88
return true if the Dimension is represented in the structure
Definition: TypeTraits.h:71
const_iterator cbegin() const
Definition: Slice.cpp:449
DimensionSize< Dimension > dimension() const
Definition: SliceTest.cpp:98
std::enable_if< std::is_same< Dim, Dimension >::value, DimensionSize< Dimension > >::type dimension() const