Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BinMapTest.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/BinMapTest.h"
25 #include "cheetah/utils/BinMap.h"
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace utils {
31 namespace test {
32 
33 
34 BinMapTest::BinMapTest()
35  : ::testing::Test()
36 {
37 }
38 
39 BinMapTest::~BinMapTest()
40 {
41 }
42 
43 void BinMapTest::SetUp()
44 {
45 }
46 
47 void BinMapTest::TearDown()
48 {
49 }
50 
51 TEST_F(BinMapTest, test_hash)
52 {
53  // Use Case:
54  // two identical maps should hash to the same value
55  BinMap<double> map1(32*256);
56  BinMap<double> map2(32*256);
57  std::size_t id1=std::hash<utils::BinMap<double>>()(map1);
58  std::size_t id2=std::hash<utils::BinMap<double>>()(map2);
59  ASSERT_EQ(id1,id2);
60  map2.set_lower_bound(10030.012);
61  ASSERT_NE(id1, std::hash<utils::BinMap<double>>()(map2));
62  map1.set_lower_bound(10030.012);
63  id1=std::hash<utils::BinMap<double>>()(map1);
64  ASSERT_EQ(id1, std::hash<utils::BinMap<double>>()(map2));
65 }
66 
67 TEST_F(BinMapTest, test_double_map)
68 {
69  utils::BinMap<double> map(32*256);
70  double start = 142.779541;
71  double width = 0.006104;
72  map.set_lower_bound(start);
73  map.set_bin_width(width);
74  ASSERT_DOUBLE_EQ( start + width/2.0, map.bin_assignment_number(0));
75  ASSERT_DOUBLE_EQ( start , map.bin_start(0));
76  ASSERT_DOUBLE_EQ( start , map.lower_bound());
77  ASSERT_DOUBLE_EQ( start + width , map.bin_end(0));
78  ASSERT_DOUBLE_EQ( start + width/2.0 + width , map.bin_assignment_number(1));
79  ASSERT_DOUBLE_EQ( start + width/2.0 + 2*width , map.bin_assignment_number(2));
80  ASSERT_EQ( 0U , map.bin_index(start) );
81  ASSERT_EQ( 1U , map.bin_index(start + width) );
82 }
83 
84 TEST_F(BinMapTest, test_negative_width)
85 {
86  utils::BinMap<double> map(32*256);
87  double start = 142.779541;
88  double width = 0.006104;
89  map.set_lower_bound(start);
90  map.set_bin_width(-1.0*width);
91  ASSERT_DOUBLE_EQ( start - width/2.0, map.bin_assignment_number(0));
92  ASSERT_DOUBLE_EQ( start , map.bin_start(0));
93  ASSERT_DOUBLE_EQ( start , map.lower_bound());
94  ASSERT_DOUBLE_EQ( start - width , map.bin_end(0));
95  ASSERT_DOUBLE_EQ( start - width/2.0 - width , map.bin_assignment_number(1));
96  ASSERT_DOUBLE_EQ( start - width/2.0 - 2*width , map.bin_assignment_number(2));
97  ASSERT_EQ( 0U , map.bin_index(start) );
98  ASSERT_EQ( 1U , map.bin_index(start - width) );
99 }
100 
101 TEST_F(BinMapTest, test_bin_width)
102 {
103  { // Use Case : Single channel - bin_width explicitly set
104  utils::BinMap<int> map(1);
105  int start = 1779541;
106  map.set_lower_bound(start);
107  int width=2;
108  map.set_bin_width(width);
109  ASSERT_EQ(width, map.bin_width());
110  }
111  { // Use Case : Single channel - bin_width set by setting start and end only
112  utils::BinMap<int> map(1);
113  int start = 1779541;
114  int width=2;
115  int end = start + width;
116  map.set_lower_bound(start);
117  map.set_upper_bound(end);
118  ASSERT_EQ(width, map.bin_width());
119  }
120 }
121 
122 } // namespace test
123 } // namespace utils
124 } // namespace cheetah
125 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35