Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataSequence2DTest.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/DataSequence2DTest.h"
25 #include "cheetah/data/DataSequence2D.h"
26 #include "cheetah/data/DataSequence2DFastIterator.h"
27 #include "cheetah/data/DataSequence2DPartialIterator.h"
28 #include <stdio.h>
29 
30 
31 namespace ska {
32 namespace cheetah {
33 namespace data {
34 namespace test {
35 
36 
37 DataSequence2DTest::DataSequence2DTest()
38 {
39 }
40 
41 DataSequence2DTest::~DataSequence2DTest()
42 {
43 }
44 
45 void DataSequence2DTest::SetUp(){}
46 void DataSequence2DTest::TearDown(){}
47 
48 TEST_F(DataSequence2DTest, test_empty)
49 {
50  data::DataSequence2D<Cpu,uint8_t> empty;
51  ASSERT_EQ(empty.fast_axis_length(),0U);
52  ASSERT_EQ(empty.slow_axis_length(),0U);
53 }
54 
55 TEST_F(DataSequence2DTest, test_create)
56 {
57  const std::size_t x=16;
58  const std::size_t y=4;
59  data::DataSequence2D<Cpu,uint8_t> ds2d(x,y);
60  ASSERT_EQ(x,ds2d.fast_axis_length());
61  ASSERT_EQ(y,ds2d.slow_axis_length());
62 }
63 
64 TEST_F(DataSequence2DTest, test_fill)
65 {
66  const std::size_t x=16;
67  const std::size_t y=4;
68  data::DataSequence2D<Cpu,uint8_t> ds2d(x,y,144);
69  ASSERT_EQ(x,ds2d.fast_axis_length());
70  ASSERT_EQ(y,ds2d.slow_axis_length());
71  for(auto v : ds2d){
72  ASSERT_EQ(uint8_t(144),v);
73  }
74 }
75 
76 
77 TEST_F(DataSequence2DTest, test_copy)
78 {
79  const std::size_t x=16;
80  const std::size_t y=4;
81  data::DataSequence2D<Cpu,uint8_t> ds2d(x,y,138);
82  ASSERT_EQ(x,ds2d.fast_axis_length());
83  ASSERT_EQ(y,ds2d.slow_axis_length());
84 
85  data::DataSequence2D<Cpu,uint8_t> ds2d_copy(x,y);
86  std::copy(ds2d.begin(), ds2d.end(), ds2d_copy.begin());
87  ASSERT_EQ(x,ds2d_copy.fast_axis_length());
88  ASSERT_EQ(y,ds2d_copy.slow_axis_length());
89  auto it = ds2d.begin();
90  auto it2 = ds2d_copy.begin();
91  while (it != ds2d.end()){
92  ASSERT_EQ(*it,*it2);
93  ++it;
94  ++it2;
95  }
96 }
97 
98 
99 TEST_F(DataSequence2DTest, test_partialfill){
100  const std::size_t l=4;
101  data::DataSequence2D<Cpu,uint8_t> ds2d(l,l,0);
102 
103  auto slice = ds2d.slice(1,3,0,2);
104 
105  while (slice != slice.end()){
106  *slice = 1;
107  ++slice;
108  }
109 
110  int x=0;
111  int y=0;
112  for (auto v : ds2d){
113  if(x >=1 && x < 3 && y >= 0 && y < 2)
114  ASSERT_EQ(1u,v);
115  else
116  ASSERT_EQ(0u,v);
117  ++x;
118  if (x == l){
119  x=0;
120  ++y;
121  }
122 
123  }
124 }
125 
126 #ifndef NDEBUG
127 TEST_F(DataSequence2DTest, test_copyfailure){
128  const std::size_t x=16;
129  const std::size_t y=4;
130  data::DataSequence2D<Cpu,uint8_t> ds2d(x,y,138);
131  ASSERT_EQ(x,ds2d.fast_axis_length());
132  ASSERT_EQ(y,ds2d.slow_axis_length());
133 
134  data::DataSequence2D<Cpu,uint8_t> ds2d_copy;
135  ASSERT_EQ(0U,ds2d_copy.fast_axis_length());
136  ASSERT_EQ(0U,ds2d_copy.slow_axis_length());
137  ASSERT_DEATH(std::copy(ds2d.begin(), ds2d.end(), ds2d_copy.begin()), "Cannot dereference*");
138 
139  data::DataSequence2D<Cpu,uint8_t> ds2d_copy2(x,2);
140  ASSERT_DEATH(std::copy(ds2d.begin(), ds2d.end(), ds2d_copy2.begin()),"Cannot dereference*");
141 
142 }
143 
144 
145 TEST_F(DataSequence2DTest, test_badslicefailure){
146  const std::size_t l=4;
147  data::DataSequence2D<Cpu,uint8_t> ds2d(l,l,0);
148 
149  ASSERT_DEATH(ds2d.slice(1,6,0,2),"Assert");
150 
151 
152 }
153 #endif
154 
155 } // namespace test
156 } // namespace data
157 } // namespace cheetah
158 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35