Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
RfiExcisionFactoryTest.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/sps/test/RfiExcisionFactoryTest.h"
25 #include "cheetah/sps/RfiExcisionConfig.h"
26 #include "cheetah/data/TimeFrequency.h"
27 #include "cheetah/data/RfimFlaggedData.h"
28 
29 namespace ska {
30 namespace cheetah {
31 namespace sps {
32 namespace test {
33 
34 
35 RfiExcisionFactoryTest::RfiExcisionFactoryTest()
36  : ::testing::Test()
37 {
38 }
39 
40 RfiExcisionFactoryTest::~RfiExcisionFactoryTest()
41 {
42 }
43 
44 void RfiExcisionFactoryTest::SetUp()
45 {
46 }
47 
48 void RfiExcisionFactoryTest::TearDown()
49 {
50 }
51 
52 TEST_F(RfiExcisionFactoryTest, test_returned_flagged_data_iterator)
53 {
54  std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>> data_ptr(new data::TimeFrequency<Cpu, uint8_t>(data::DimensionSize<data::Time>(1000), data::DimensionSize<data::Frequency>(10)));
55  data::RfimFlaggedData<data::TimeFrequency<Cpu, uint8_t>> flagged_data(data::DimensionSize<data::Time>(1000), data::DimensionSize<data::Frequency>(10));
56  RfiExcisionConfig config;
57  RfiExcisionFactory<data::TimeFrequency<Cpu, uint8_t>> it_factory(config);
58  auto it = it_factory.begin(flagged_data);
59  RfiExcision<data::TimeFrequency<Cpu, uint8_t>, decltype(flagged_data)> it1(flagged_data, 0, 7.0, 5.0, false);
60  ASSERT_TRUE(it1 == it);
61  auto it_end = it_factory.end(flagged_data);
62  RfiExcision<data::TimeFrequency<Cpu, uint8_t>, decltype(flagged_data)> it1_end(flagged_data, 10000, 7.0, 5.0, false);
63  ASSERT_TRUE(it1_end == it_end);
64 }
65 
66 TEST_F(RfiExcisionFactoryTest, test_returned_tf_data_iterator)
67 {
68  data::TimeFrequency<Cpu, uint8_t> data(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(1024));
69  RfiExcisionConfig config;
70  RfiExcisionFactory<decltype(data)> it_factory(config);
71  auto it = it_factory.begin(data);
72  auto it_end = it_factory.end(data);
73  ASSERT_EQ(data.begin(), it);
74  ASSERT_EQ(data.end(), it_end);
75 }
76 
77 TEST_F(RfiExcisionFactoryTest, test_returned_const_tf_data_iterator)
78 {
79  const data::TimeFrequency<Cpu, uint8_t> data(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(1024));
80  RfiExcisionConfig config;
81  RfiExcisionFactory<decltype(data)> it_factory(config);
82  auto it = it_factory.begin(data);
83  auto it_end = it_factory.end(data);
84  ASSERT_EQ(data.begin(), it);
85  ASSERT_EQ(data.end(), it_end);
86 }
87 
88 TEST_F(RfiExcisionFactoryTest, test_correct_returned_value)
89 {
90  std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>> data_ptr(new data::TimeFrequency<Cpu, uint8_t>(data::DimensionSize<data::Time>(16), data::DimensionSize<data::Frequency>(8)));
91  uint8_t n=0;
92  std::generate((*data_ptr).begin(),(*data_ptr).end(),[&](){return ++n;});
93  data::RfimFlaggedData<data::TimeFrequency<Cpu, uint8_t>> flagged_data((*data_ptr));
94  // Set all flags to false
95  flagged_data.rfi_flags().reset(false);
96  RfiExcision<data::TimeFrequency<Cpu, uint8_t>, decltype(flagged_data)> it(flagged_data, 0, 7.0, 5.0, false);
97 
98  auto data_it = flagged_data.tf_data().begin();
99 
100  // Check if we get the correct numerical rep from the full chunk
101  for (std::uint32_t ii=0; ii < 127; ++ii)
102  {
103  ++it;
104  ++data_it;
105  ASSERT_EQ(*it, *data_it);
106  }
107 }
108 
109 TEST_F(RfiExcisionFactoryTest, test_end_iterator)
110 {
111  std::shared_ptr<data::TimeFrequency<Cpu, uint8_t>> data_ptr(new data::TimeFrequency<Cpu, uint8_t>(data::DimensionSize<data::Time>(1000), data::DimensionSize<data::Frequency>(10)));
112  std::fill((*data_ptr).begin(), (*data_ptr).end(), 1U);
113  RfiExcisionConfig config;
114  data::RfimFlaggedData<data::TimeFrequency<Cpu, uint8_t>> flagged_data((*data_ptr));
115  RfiExcisionFactory<data::TimeFrequency<Cpu, uint8_t>> it_factory(config);
116  auto it = it_factory.end(flagged_data);
117 
118  RfiExcision<data::TimeFrequency<Cpu, uint8_t>,decltype(flagged_data)> it2(flagged_data, flagged_data.tf_data().data_size(), 7.0, 5.0, false);
119  ASSERT_EQ(it,it2);
120 }
121 
122 } // namespace test
123 } // namespace sps
124 } // namespace cheetah
125 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35