JayBeams  0.1
Another project to have fun coding.
ut_cast_vector.cpp
Go to the documentation of this file.
2 #include <jb/fftw/cast.hpp>
3 
4 #include <boost/test/unit_test.hpp>
5 
6 /**
7  * Helper functions to test fftw_cast
8  */
9 namespace {
10 
11 /// Test cast functions for a given vector type
12 template <typename vector_type, typename expected>
13 void check_cast_vector() {
14  BOOST_TEST_MESSAGE("Testing in " << __FUNCTION__);
15  std::size_t const N = 1 << 15;
16 
17  vector_type v(N);
18  auto p = jb::fftw::fftw_cast(v);
19  bool actual = std::is_same<decltype(p), expected>::value;
20  BOOST_CHECK_EQUAL(actual, true);
21 }
22 
23 } // anonymous namespace
24 
25 /**
26  * @test Verify that fftw_cast functions work for std::vector<float>
27  */
28 BOOST_AUTO_TEST_CASE(fftw_cast_vector_float) {
29  check_cast_vector<std::vector<float>, float*>();
30  check_cast_vector<std::vector<float> const, float const*>();
31 
32  check_cast_vector<jb::fftw::aligned_vector<float>, float*>();
33  check_cast_vector<jb::fftw::aligned_vector<float> const, float const*>();
34 }
35 
36 /**
37  * @test Verify that fftw_cast functions work for std::vector<double>
38  */
39 BOOST_AUTO_TEST_CASE(fftw_cast_vector_double) {
40  check_cast_vector<std::vector<double>, double*>();
41  check_cast_vector<std::vector<double> const, double const*>();
42 
43  check_cast_vector<jb::fftw::aligned_vector<double>, double*>();
44  check_cast_vector<jb::fftw::aligned_vector<double> const, double const*>();
45 }
46 
47 /**
48  * @test Verify that fftw_cast functions work for std::vector<long double>
49  */
50 BOOST_AUTO_TEST_CASE(fftw_cast_vector_long_double) {
51  check_cast_vector<std::vector<long double>, long double*>();
52  check_cast_vector<std::vector<long double> const, long double const*>();
53 
54  check_cast_vector<jb::fftw::aligned_vector<long double>, long double*>();
55  check_cast_vector<
56  jb::fftw::aligned_vector<long double> const, long double const*>();
57 }
58 
59 /**
60  * @test Verify that fftw_cast functions work for
61  * std::vector<std::complex<float>>
62  */
63 BOOST_AUTO_TEST_CASE(fftw_cast_vector_complex_float) {
64  check_cast_vector<std::vector<std::complex<float>>, fftwf_complex*>();
65  check_cast_vector<
66  std::vector<std::complex<float>> const, fftwf_complex const*>();
67 
68  check_cast_vector<
70  check_cast_vector<
71  jb::fftw::aligned_vector<std::complex<float>> const,
72  fftwf_complex const*>();
73 }
74 
75 /**
76  * @test Verify that fftw_cast functions work for
77  * std::vector<std::complex<double>>
78  */
79 BOOST_AUTO_TEST_CASE(fftw_cast_vector_complex_double) {
80  check_cast_vector<std::vector<std::complex<double>>, fftw_complex*>();
81  check_cast_vector<
82  std::vector<std::complex<double>> const, fftw_complex const*>();
83 
84  check_cast_vector<
86  check_cast_vector<
87  jb::fftw::aligned_vector<std::complex<double>> const,
88  fftw_complex const*>();
89 }
90 
91 /**
92  * @test Verify that fftw_cast functions work for
93  * std::vector<std::complex<long double>>
94  */
95 BOOST_AUTO_TEST_CASE(fftw_cast_vector_complex_long_double) {
96  check_cast_vector<std::vector<std::complex<long double>>, fftwl_complex*>();
97  check_cast_vector<
98  std::vector<std::complex<long double>> const, fftwl_complex const*>();
99 
100  check_cast_vector<
102  check_cast_vector<
103  jb::fftw::aligned_vector<std::complex<long double>> const,
104  fftwl_complex const*>();
105 }
std::vector< T, jb::fftw::allocator< T > > aligned_vector
Alias std::vector with properly allocated storage for FFTW3.
auto fftw_cast(vector &in) -> decltype(fftw_cast_array(&in[0]))
Definition: cast.hpp:33
BOOST_AUTO_TEST_CASE(fftw_cast_vector_float)