Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
ConvolvePlanTest.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/utils/test/ConvolvePlanTest.h"
25 #include "cheetah/utils/ConvolvePlan.h"
26 #include <array>
27 #include <algorithm>
28 
29 namespace ska {
30 namespace cheetah {
31 namespace utils {
32 namespace test {
33 
34 
35 ConvolvePlanTest::ConvolvePlanTest()
36  : ::testing::Test()
37 {
38 }
39 
40 ConvolvePlanTest::~ConvolvePlanTest()
41 {
42 }
43 
44 void ConvolvePlanTest::SetUp()
45 {
46 }
47 
48 void ConvolvePlanTest::TearDown()
49 {
50 }
51 
52 TEST_F(ConvolvePlanTest, test_all_null_function)
53 {
54  constexpr std::size_t npts=100;
55  std::array<float, npts> a;
56  std::fill(a.begin(), a.end(), 0.0);
57  std::array<float, npts> b;
58  std::fill(b.begin(), b.end(), 0.0);
59  std::array<float, npts+1> output;
60  std::fill(output.begin(), output.end(), 0.0);
61 
62  utils::ConvolvePlan plan(npts, a.data(), b.data(), output.data());
63  plan.convolve();
64  std::for_each(output.begin(), output.end(), [](float t) { ASSERT_EQ(0.0, t); });
65 }
66 
67 TEST_F(ConvolvePlanTest, test_a_null_function)
68 {
69  constexpr std::size_t npts=100;
70  std::array<float, npts> a;
71  std::fill(a.begin(), a.end(), 0.0);
72  std::array<float, npts> b;
73  std::fill(b.begin(), b.end(), 1.0);
74  std::array<float, npts+1> output;
75  std::fill(output.begin(), output.end(), 0.0);
76 
77  utils::ConvolvePlan plan(npts, a.data(), b.data(), output.data());
78  plan.convolve();
79  std::for_each(output.begin(), output.end(), [](float t) { ASSERT_EQ(0.0, t); });
80 }
81 
82 TEST_F(ConvolvePlanTest, test_b_null_function)
83 {
84  constexpr std::size_t npts=100;
85  std::array<float, npts> a;
86  std::fill(a.begin(), a.end(), 1.0);
87  std::array<float, npts> b;
88  std::fill(b.begin(), b.end(), 0.0);
89  std::array<float, npts+1> output;
90  std::fill(output.begin(), output.end(), 0.0);
91 
92  utils::ConvolvePlan plan(npts, a.data(), b.data(), output.data());
93  plan.convolve();
94  std::for_each(output.begin(), output.end(), [](float t) { ASSERT_EQ(0.0, t); });
95 }
96 
97 TEST_F(ConvolvePlanTest, test_a_equal_b)
98 {
99  constexpr std::size_t npts=100;
100  std::array<float, npts> a;
101  std::fill(a.begin(), a.end(), 1.0);
102  std::array<float, npts> b;
103  std::fill(b.begin(), b.end(), 1.0);
104  std::array<float, npts+1> output;
105  std::fill(output.begin(), output.end(), 0.0);
106 
107  utils::ConvolvePlan plan(npts, a.data(), b.data(), output.data());
108  plan.convolve();
109  ASSERT_EQ(0.0, output.back()); // check no buffer overwrite
110  std::for_each(output.begin(), output.end() - 1, [&](float t) { ASSERT_EQ(100.0, t); });
111 }
112 
113 } // namespace test
114 } // namespace utils
115 } // namespace cheetah
116 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35