map_primitives_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <algorithm>
4 
5 #include "../../../src/utils/data_generation/map_primitives.h"
6 
7 class CecumTextRasterMapPrimitiveTest : public ::testing::Test {
8 protected:
10 protected: // methods
12 
13  std::string to_str(const CecumTextRasterMapPrimitive &cecum_mp) {
14  auto str = std::string{};
15 
16  std::istream& txt_stream = cecum_mp.to_stream();
17  auto buf = std::string{};
18  while (txt_stream.good()) {
19  std::getline(txt_stream, buf);
20  str += buf;
21  }
22  return str;
23  }
24 
25  std::string pattern_to_expected(const std::string &pattern) {
26  std::string result = pattern;
27  std::replace(result.begin(), result.end(),
29  std::replace(result.begin(), result.end(),
31  return result;
32  }
33 };
34 
35 //------------------------------------------------------------------------------
36 // Degenerate cases
37 
39  auto cecum_mp = CecumTextRasterMapPrimitive{1, 1, CecumMPBndPos::Top};
40 
41  const std::string Map_Pattern = "1";
42  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
43  ASSERT_EQ(1, cecum_mp.width());
44  ASSERT_EQ(1, cecum_mp.height());
45  ASSERT_EQ(1, cecum_mp.free_space().size());
46  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
47 }
48 
49 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelWidthTop) {
50  auto cecum_mp = CecumTextRasterMapPrimitive{1, 2, CecumMPBndPos::Top};
51 
52  const std::string Map_Pattern = "1"
53  "1";
54  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
55  ASSERT_EQ(1, cecum_mp.width());
56  ASSERT_EQ(2, cecum_mp.height());
57  ASSERT_EQ(1, cecum_mp.free_space().size());
58  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
59 }
60 
61 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelHeightTop) {
62  auto cecum_mp = CecumTextRasterMapPrimitive{3, 1, CecumMPBndPos::Top};
63 
64  const std::string Map_Pattern = "111";
65  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
66  ASSERT_EQ(3, cecum_mp.width());
67  ASSERT_EQ(1, cecum_mp.height());
68  ASSERT_EQ(1, cecum_mp.free_space().size());
69  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
70 }
71 
72 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelHeightBot) {
73  auto cecum_mp = CecumTextRasterMapPrimitive{3, 1, CecumMPBndPos::Bot};
74 
75  const std::string Map_Pattern = "111";
76  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
77  ASSERT_EQ(3, cecum_mp.width());
78  ASSERT_EQ(1, cecum_mp.height());
79  ASSERT_EQ(1, cecum_mp.free_space().size());
80  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
81 }
82 
84  auto cecum_mp = CecumTextRasterMapPrimitive{1, 1, CecumMPBndPos::Left};
85 
86  const std::string Map_Pattern = "1";
87  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
88  ASSERT_EQ(1, cecum_mp.width());
89  ASSERT_EQ(1, cecum_mp.height());
90  ASSERT_EQ(1, cecum_mp.free_space().size());
91  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
92 }
93 
94 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelWidthLeft) {
95  auto cecum_mp = CecumTextRasterMapPrimitive{1, 3, CecumMPBndPos::Left};
96 
97  const std::string Map_Pattern = "1"
98  "1"
99  "1";
100  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
101  ASSERT_EQ(1, cecum_mp.width());
102  ASSERT_EQ(3, cecum_mp.height());
103  ASSERT_EQ(1, cecum_mp.free_space().size());
104  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
105 }
106 
107 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelWidthRight) {
108  auto cecum_mp = CecumTextRasterMapPrimitive{1, 3, CecumMPBndPos::Right};
109 
110  const std::string Map_Pattern = "1"
111  "1"
112  "1";
113  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
114  ASSERT_EQ(1, cecum_mp.width());
115  ASSERT_EQ(3, cecum_mp.height());
116  ASSERT_EQ(1, cecum_mp.free_space().size());
117  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
118 }
119 
120 TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelHeightRight) {
121  auto cecum_mp = CecumTextRasterMapPrimitive{5, 1, CecumMPBndPos::Right};
122 
123  const std::string Map_Pattern = "11111";
124  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
125  ASSERT_EQ(5, cecum_mp.width());
126  ASSERT_EQ(1, cecum_mp.height());
127  ASSERT_EQ(1, cecum_mp.free_space().size());
128  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
129 }
130 
131 //------------------------------------------------------------------------------
132 // No free space cases
133 
135  auto cecum_mp = CecumTextRasterMapPrimitive{2, 3, CecumMPBndPos::Top};
136 
137  const std::string Map_Pattern = "11"
138  "11"
139  "11";
140  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
141  ASSERT_EQ(2, cecum_mp.width());
142  ASSERT_EQ(3, cecum_mp.height());
143  ASSERT_EQ(1, cecum_mp.free_space().size());
144  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
145 }
146 
148  auto cecum_mp = CecumTextRasterMapPrimitive{2, 4, CecumMPBndPos::Bot};
149 
150  const std::string Map_Pattern = "11"
151  "11"
152  "11"
153  "11";
154  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
155  ASSERT_EQ(2, cecum_mp.width());
156  ASSERT_EQ(4, cecum_mp.height());
157  ASSERT_EQ(1, cecum_mp.free_space().size());
158  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
159 }
160 
162  auto cecum_mp = CecumTextRasterMapPrimitive{4, 2, CecumMPBndPos::Left};
163 
164  const std::string Map_Pattern = "1111"
165  "1111";
166  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
167  ASSERT_EQ(4, cecum_mp.width());
168  ASSERT_EQ(2, cecum_mp.height());
169  ASSERT_EQ(1, cecum_mp.free_space().size());
170  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
171 }
172 
174  auto cecum_mp = CecumTextRasterMapPrimitive{5, 2, CecumMPBndPos::Right};
175 
176  const std::string Map_Pattern = "11111"
177  "11111";
178  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
179  ASSERT_EQ(5, cecum_mp.width());
180  ASSERT_EQ(2, cecum_mp.height());
181  ASSERT_EQ(1, cecum_mp.free_space().size());
182  ASSERT_EQ(0, cecum_mp.free_space()[0].area());
183 }
184 
185 //------------------------------------------------------------------------------
186 // Common cases
187 
189  auto cecum_mp = CecumTextRasterMapPrimitive{5, 4, CecumMPBndPos::Top};
190 
191  const std::string Map_Pattern = "11111"
192  "10001"
193  "10001"
194  "10001";
195  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
196  ASSERT_EQ(5, cecum_mp.width());
197  ASSERT_EQ(4, cecum_mp.height());
198  ASSERT_EQ(1, cecum_mp.free_space().size());
199  ASSERT_EQ(Rectangle(-3, 0, 1, 4), cecum_mp.free_space()[0]);
200 }
201 
203  auto cecum_mp = CecumTextRasterMapPrimitive{6, 3, CecumMPBndPos::Bot};
204 
205  const std::string Map_Pattern = "100001"
206  "100001"
207  "111111";
208  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
209  ASSERT_EQ(6, cecum_mp.width());
210  ASSERT_EQ(3, cecum_mp.height());
211  ASSERT_EQ(1, cecum_mp.free_space().size());
212  ASSERT_EQ(Rectangle(-1, 1, 1, 5), cecum_mp.free_space()[0]);
213 }
214 
216  auto cecum_mp = CecumTextRasterMapPrimitive{6, 4, CecumMPBndPos::Left};
217 
218  const std::string Map_Pattern = "111111"
219  "100000"
220  "100000"
221  "111111";
222  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
223  ASSERT_EQ(6, cecum_mp.width());
224  ASSERT_EQ(4, cecum_mp.height());
225  ASSERT_EQ(1, cecum_mp.free_space().size());
226  ASSERT_EQ(Rectangle(-2, 0, 1, 6), cecum_mp.free_space()[0]);
227 }
228 
230  auto cecum_mp = CecumTextRasterMapPrimitive{7, 5, CecumMPBndPos::Right};
231 
232  const std::string Map_Pattern = "1111111"
233  "0000001"
234  "0000001"
235  "0000001"
236  "1111111";
237  ASSERT_EQ(pattern_to_expected(Map_Pattern), to_str(cecum_mp));
238  ASSERT_EQ(7, cecum_mp.width());
239  ASSERT_EQ(5, cecum_mp.height());
240  ASSERT_EQ(1, cecum_mp.free_space().size());
241  ASSERT_EQ(Rectangle(-3, 0, 0, 6), cecum_mp.free_space()[0]);
242 }
243 
244 //------------------------------------------------------------------------------
245 
246 int main (int argc, char *argv[]) {
247  ::testing::InitGoogleTest(&argc, argv);
248  return RUN_ALL_TESTS();
249 }
int main(int argc, char *argv[])
std::istream & to_stream() const override
static constexpr char Completely_Free_Marker
std::string pattern_to_expected(const std::string &pattern)
static constexpr char Completely_Occupied_Marker
TEST_F(CecumTextRasterMapPrimitiveTest, singlePixelTop)
std::string to_str(const CecumTextRasterMapPrimitive &cecum_mp)


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25