Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
TimeFrequencyFlagsTest.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/TimeFrequencyFlagsTest.h"
25 #include "cheetah/data/TimeFrequencyFlags.h"
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace data {
31 namespace test {
32 
33 
34 TimeFrequencyFlagsTest::TimeFrequencyFlagsTest()
35  : ::testing::Test()
36 {
37 }
38 
39 TimeFrequencyFlagsTest::~TimeFrequencyFlagsTest()
40 {
41 }
42 
43 void TimeFrequencyFlagsTest::SetUp()
44 {
45 }
46 
47 void TimeFrequencyFlagsTest::TearDown()
48 {
49 }
50 
51 TEST_F(TimeFrequencyFlagsTest, test_meta)
52 {
53  DimensionSize<Time> number_of_spectra(10U);
54  DimensionSize<Frequency> number_of_channels(5U);
55  data::TimeFrequencyFlags<Cpu> tf(number_of_spectra, number_of_channels);
56  ASSERT_EQ(number_of_spectra, tf.number_of_spectra());
57  ASSERT_EQ(number_of_channels, tf.number_of_channels());
58 }
59 
60 TEST_F(TimeFrequencyFlagsTest, test_time_sample)
61 {
62  DimensionSize<Time> number_of_spectra(10U);
63  DimensionSize<Frequency> number_of_channels(5U);
64  data::TimeFrequencyFlags<Cpu> tf(number_of_spectra, number_of_channels);
65  for(unsigned n=0; n< number_of_spectra; ++n) {
66  auto time_sample = tf.spectrum(n);
67  auto const_time_sample = static_cast<const data::TimeFrequencyFlags<Cpu>>(tf).spectrum(n);
68  ASSERT_EQ(number_of_channels, time_sample.end() - time_sample.begin());
69  ASSERT_EQ(number_of_channels, const_time_sample.end() - const_time_sample.begin());
70  }
71 }
72 
73 TEST_F(TimeFrequencyFlagsTest, test_begin_end_reset)
74 {
75  DimensionSize<Time> number_of_spectra(10U);
76  DimensionSize<Frequency> number_of_channels(5U);
77  data::TimeFrequencyFlags<Cpu> tf(number_of_spectra, number_of_channels);
78  tf.reset(false);
79  auto it = tf.begin();
80 
81  ASSERT_EQ(number_of_channels * number_of_spectra, tf.end() - it);
82  std::size_t count = 0;
83  while(it != tf.end()) {
84  ASSERT_FALSE(*it);
85  ++count;
86  ++it;
87  }
88  ASSERT_EQ(std::size_t(number_of_channels * number_of_spectra), count);
89 
90  // set all to true
91  tf.reset(true);
92  count = 0;
93  it = tf.begin();
94  while(it != tf.end()) {
95  ASSERT_TRUE(*it);
96  ++count;
97  ++it;
98  }
99  ASSERT_EQ(std::size_t(number_of_channels * number_of_spectra), count);
100 }
101 
102 TEST_F(TimeFrequencyFlagsTest, test_channel)
103 {
104  DimensionSize<Time> number_of_spectra(10U);
105  DimensionSize<Frequency> number_of_channels(5U);
106  data::TimeFrequencyFlags<Cpu> tf(number_of_spectra, number_of_channels);
107  tf.reset(false);
108  for(unsigned n=0; n< number_of_channels; ++n) {
109  auto channel_sample = tf.channel(n);
110  auto it = channel_sample.begin();
111  std::size_t count=0;
112  while(it != channel_sample.end()) {
113  *it = true;
114  ++count;
115  ++it;
116  }
117  ASSERT_EQ(number_of_spectra, count);
118  ASSERT_EQ(number_of_spectra, channel_sample.end() - channel_sample.begin());
119  //ASSERT_EQ(number_of_spectra, std::distance(channel_sample.begin() , channel_sample.end()));
120  //
121  // verify we have set the value and reset to zero
122  for(unsigned nv=0; nv< number_of_channels; ++nv) {
123  auto channel_sample = tf.channel(nv);
124  auto it = channel_sample.begin();
125  while(it != channel_sample.end()) {
126  if(nv==n) {
127  ASSERT_TRUE(*it);
128  }
129  else {
130  ASSERT_FALSE(*it);
131  }
132  ++it;
133  }
134  }
135  // reset the channel
136  it = channel_sample.begin();
137  while(it != channel_sample.end()) {
138  *it = false;
139  ++it;
140  }
141  }
142 }
143 
144 } // namespace test
145 } // namespace data
146 } // namespace cheetah
147 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35