Waveform
Waveform is a C++ header-only library which represents both the time and the frequency domains of a waveform/signal as a single object, transforming using FFTW automatically when needed.
 All Classes Namespaces Functions Typedefs Friends Groups
IdentityTransform_test.cpp
1 
2 
3 #include <iostream>
4 
5 
6 #include <typeinfo>
7 #include <functional>
8 
9 #include <vector>
10 #include <IdentityTransform.hpp>
11 
12 #include <boost/range.hpp>
13 #include <boost/range/algorithm.hpp>
14 #include <boost/range/algorithm_ext.hpp>
15 
16 #include <gtest/gtest.h>
17 
18 
19 
20 
21 namespace {
22 
23 
24 class IdentityTest : public ::testing::Test {
25  protected:
26 
27  IdentityTest()
28  {
29 
30  }
31 
32 
33  virtual
34  ~IdentityTest()
35  {
36 
37  }
38 
39 
40  virtual
41  void
42  SetUp()
43  {
44 
45  reference_vec.resize(ref_vec_len);
46 
47  boost::iota (reference_vec, 0);
48 
49  }
50 
51 
52  virtual
53  void
54  TearDown()
55  {
56 
57  }
58 
59  const std::size_t ref_vec_len = 512;
60  //std::vector<int> reference_vec (ref_vec_len);
61  //std::vector<int> reference_vec (512);
62  std::vector<int> reference_vec;
63 };
64 
65 
66 typedef std::vector<int> VT;
67 
69 //typedef Waveform::Transform::Identity<std::vector<int>> IdentityT;
70 
71 
72 
73 TEST_F(IdentityTest, CTor1)
74 {
75  // Create the first "domain" array for the transform
76  //std::vector<int> vec (512, 0);
77  VT vec (reference_vec);
78 
79  // Fill the array with incremental values
80  //boost::iota (vec, 0);
81 
82  // Create the second "domain" array with the same length as the first
83  VT vec2 (vec.size());
84  //std::vector<int> vec2 (vec.size());
85 
86  // Create the transform from the two domain arrays
87  IdentityT idT (vec.begin(), vec.end(), vec2.begin());
88 
89  // Compare the values against the reference values
90  for (std::size_t i = 0; i < vec.size(); ++i)
91  {
92  EXPECT_EQ( reference_vec.at(i), vec.at(i) );
93  }
94 }
95 
96 
97 
98 TEST_F(IdentityTest, CTor2)
99 {
100  // Create the first "domain" array for the transform
101 // std::vector<int> vec (512, 0);
102  VT vec (reference_vec);
103 
104  // Fill the array with incremental values
105 // boost::iota (vec, 0);
106 
107  // Create the second "domain" array with the same length as the first
108 // std::vector<int> vec2 (vec.size());
109  VT vec2 (vec.size());
110 
111  // Create the transform from the two domain arrays
112  IdentityT idT (vec,vec2);
113 
114  // Compare the values against the reference values
115  for (std::size_t i = 0; i < vec.size(); ++i)
116  {
117  EXPECT_EQ( reference_vec.at(i), vec.at(i) );
118  }
119 
120 }
121 
122 TEST_F(IdentityTest, SeeTypes)
123 {
124  VT vec (reference_vec);
125  VT vec2 (vec.size());
126  IdentityT idT (vec,vec2);
127 
128 
129  std::cout << "Transform Type: " << typeid(decltype(idT)::transform_type).name() << std::endl;
130 
131 
132 }
133 
134 
135 TEST_F(IdentityTest, FwTransWithIters)
136 {
137  // Create the first "domain" array for the transform
138 // std::vector<int> vec (512, 0);
139  VT vec (reference_vec);
140 
141  // Fill the array with incremental values
142 // boost::iota (vec, 0);
143 
144  // Create the second "domain" array with the same length as the first
145  //std::vector<int> vec2 (vec.size());
146  VT vec2 (vec.size());
147 
148  // Create the transform from the two domain arrays
149  //IdentityT idT (vec, vec2);
150  IdentityT idT (vec.begin(), vec.end(), vec2.begin());
151 
152  // Execute the transform
153  idT.exec_transform();
154 
155  // Compare the values against the reference values
156  for (std::size_t i = 0; i < vec.size(); ++i)
157  {
158  EXPECT_EQ( reference_vec.at(i), vec.at(i) );
159  }
160 
161  // Compare the values against the reference values
162  for (std::size_t i = 0; i < vec.size(); ++i)
163  {
164  EXPECT_EQ( reference_vec.at(i), vec2.at(i) );
165  }
166 }
167 
168 
169 TEST_F(IdentityTest, FwTransWithRange)
170 {
171  // Create the first "domain" array for the transform
172 // std::vector<int> vec (512, 0);
173  VT vec (reference_vec);
174 
175  // Fill the array with incremental values
176 // boost::iota (vec, 0);
177 
178  // Create the second "domain" array with the same length as the first
179  //std::vector<int> vec2 (vec.size());
180  VT vec2 (vec.size());
181 
182  // Create the transform from the two domain arrays
183  IdentityT idT (vec, vec2);
184  //IdentityT idT (vec.begin(), vec.end(), vec2.begin());
185 
186  // Execute the transform
187  idT.exec_transform();
188 
189  // Compare the values against the reference values
190  for (std::size_t i = 0; i < vec.size(); ++i)
191  {
192  EXPECT_EQ( reference_vec.at(i), vec.at(i) );
193  }
194 
195  // Compare the values against the reference values
196  for (std::size_t i = 0; i < vec.size(); ++i)
197  {
198  EXPECT_EQ( reference_vec.at(i), vec2.at(i) );
199  }
200 
201  EXPECT_EQ( vec.begin(), boost::begin(idT.range1_));
202  EXPECT_EQ( vec.end(), boost::end(idT.range1_));
203  EXPECT_EQ( vec2.begin(), boost::begin(idT.range2_));
204  EXPECT_EQ( vec2.end(), boost::end(idT.range2_));
205 }
206 
207 
208 TEST_F(IdentityTest, InvTrans)
209 {
210  // Create the first "domain" array for the transform
211  //std::vector<int> vec (512, 0);
212  VT vec (reference_vec);
213 
214  // Create the second "domain" array with the same length as the first
215  //std::vector<int> vec2 (vec.size());
216  VT vec2 (vec.size());
217 
218  // Fill the array with incremental values
219  //boost::iota (vec2, 0);
220 
221  // Create the transform from the two domain arrays
222  //IdentityT idT (vec, vec2);
223  IdentityT idT (vec2.begin(), vec2.end(), vec.begin());
224 
225  // Execute the inverse transform
226  idT.exec_inverse_transform();
227 
228  // Compare the values against the reference values
229  for (std::size_t i = 0; i < vec.size(); ++i)
230  {
231  EXPECT_EQ( reference_vec.at(i), vec.at(i) );
232  }
233 
234  // Compare the values against the reference values
235  for (std::size_t i = 0; i < vec.size(); ++i)
236  {
237  EXPECT_EQ( reference_vec.at(i), vec2.at(i) );
238  }
239 
240 }
241 
242 
243 
244 
245 
246 
247 } // namespace
248 
249 
250 int
251 main (int argc, char** argv)
252 {
253  ::testing::InitGoogleTest(&argc, argv);
254  return RUN_ALL_TESTS();
255 }