Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SeriesTester.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
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 "cheetah/data/test_utils/SeriesTester.h"
25 #include "cheetah/data/Series.h"
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace data {
31 namespace test {
32 
33 
34 template<typename SeriesTesterTraitsT>
35 SeriesTester<SeriesTesterTraitsT>::SeriesTester()
36 {
37 }
38 
39 TYPED_TEST_P(SeriesTester, construct_resize)
40 {
41  typedef TypeParam Traits;
42  typedef typename Traits::SeriesType SeriesType;
43 
44  Traits traits;
45  for(auto& device : this->_system.devices()) {
46  SeriesType series(traits.allocator(*device));
47  ASSERT_EQ(series.size(), std::size_t(0));
48  // increase size
49  series.resize(2);
50  ASSERT_EQ(series.size(), std::size_t(2));
51  // reduce ize
52  series.resize(1);
53  ASSERT_EQ(series.size(), std::size_t(1));
54  // resize to exisiting size should do nothing
55  auto it = series.begin();
56  series.resize(1);
57  ASSERT_EQ(series.size(), std::size_t(1));
58  ASSERT_EQ(it, series.begin());
59  }
60 }
61 
62 TYPED_TEST_P(SeriesTester, begin_end)
63 {
64  typedef TypeParam Traits;
65  typedef typename Traits::SeriesType SeriesType;
66 
67  Traits traits;
68  std::size_t n=2;
69  for(auto& device : this->_system.devices()) {
70  SeriesType series(n, traits.allocator(*device));
71 
72  // begin end on non-const object
73  std::size_t count=0;
74  {
75  auto it = series.begin();
76  ASSERT_EQ(n, std::size_t(std::distance(it, series.end())));
77  while(it != series.end()) {
78  ++count;
79  ++it;
80  }
81  ASSERT_EQ(count, n);
82  }
83 
84  // begin end on const object
85  const SeriesType& const_series = series;
86  {
87  count=0;
88  auto it = const_series.begin();
89  ASSERT_EQ(n, std::size_t(std::distance(it, const_series.end())));
90  while(it != const_series.end()) {
91  ++count;
92  ++it;
93  }
94  ASSERT_EQ(count, n);
95  }
96 
97  // cbegin cend on const object
98  {
99  count=0;
100  auto it = const_series.cbegin();
101  ASSERT_EQ(n, std::size_t(std::distance(it, series.cend())));
102  while(it != const_series.cend()) {
103  ++count;
104  ++it;
105  }
106  ASSERT_EQ(count, n);
107  }
108  }
109 }
110 
111 TYPED_TEST_P(SeriesTester, host_conversion)
112 {
113  typedef TypeParam Traits;
114  typedef typename Traits::SeriesType SeriesType;
115  typedef typename SeriesType::ValueType ValueType;
116  typedef Series<panda::Cpu, ValueType, std::allocator<ValueType>> HostSeriesType;
117 
118  // some host based data
119  std::size_t n=5;
120  HostSeriesType host_data(n, std::allocator<ValueType>());
121  ValueType value=0;
122  std::transform(host_data.begin(), host_data.end(), host_data.begin(), [&](ValueType const&) { return ++value; });
123 
124  Traits traits;
125  for(auto& device : this->_system.devices()) {
126  // copy host data to target Series
127  auto allocator = traits.allocator(*device);
128  SeriesType series(host_data, allocator);
129  ASSERT_EQ(series.size(), host_data.size());
130  // copy back from target to host
131  HostSeriesType host_data_copy(series);
132  ASSERT_EQ(host_data_copy.size(), n);
133  auto copy_it=host_data_copy.cbegin();
134  auto it=host_data.cbegin();
135  std::size_t count=0;
136  while(it!=host_data.cend()) {
137  SCOPED_TRACE("element number: " + std::to_string(count));
138  ASSERT_EQ(*it, *copy_it) << host_data[count];
139  ++it;
140  ++copy_it;
141  ++count;
142  }
143  }
144 }
145 
146 REGISTER_TYPED_TEST_CASE_P(SeriesTester, construct_resize, begin_end, host_conversion);
147 
148 } // namespace test
149 } // namespace data
150 } // namespace cheetah
151 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35