LineIteratorTest.cpp
Go to the documentation of this file.
1 /*
2  * LineIteratorTest.cpp
3  *
4  * Created on: Sep 14, 2016
5  * Author: Dominic Jud
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
11 
12 // gtest
13 #include <gtest/gtest.h>
14 
15 // Limits
16 #include <cfloat>
17 
18 using namespace grid_map;
19 
20 TEST(LineIterator, StartOutsideMap)
21 {
22  GridMap map( { "types" });
23  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
24 
25  EXPECT_NO_THROW(LineIterator iterator(map, Position(2.0, 2.0), Position(0.0, 0.0)));
26  LineIterator iterator(map, Position(2.0, 2.0), Position(0.0, 0.0));
27 
28  EXPECT_FALSE(iterator.isPastEnd());
29  EXPECT_EQ(2, (*iterator)(0));
30  EXPECT_EQ(0, (*iterator)(1));
31 
32  ++iterator;
33  EXPECT_FALSE(iterator.isPastEnd());
34  EXPECT_EQ(3, (*iterator)(0));
35  EXPECT_EQ(1, (*iterator)(1));
36 
37  ++iterator;
38  EXPECT_FALSE(iterator.isPastEnd());
39  EXPECT_EQ(4, (*iterator)(0));
40  EXPECT_EQ(2, (*iterator)(1));
41 
42  ++iterator;
43  EXPECT_TRUE(iterator.isPastEnd());
44 }
45 
46 TEST(LineIterator, EndOutsideMap)
47 {
48  GridMap map( { "types" });
49  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
50 
51  EXPECT_NO_THROW(LineIterator iterator(map, Position(0.0, 0.0), Position(9.0, 6.0)));
52  LineIterator iterator(map, Position(0.0, 0.0), Position(9.0, 6.0));
53 
54  EXPECT_FALSE(iterator.isPastEnd());
55  EXPECT_EQ(4, (*iterator)(0));
56  EXPECT_EQ(2, (*iterator)(1));
57 
58  ++iterator;
59  EXPECT_FALSE(iterator.isPastEnd());
60  EXPECT_EQ(3, (*iterator)(0));
61  EXPECT_EQ(1, (*iterator)(1));
62 
63  ++iterator;
64  EXPECT_FALSE(iterator.isPastEnd());
65  EXPECT_EQ(2, (*iterator)(0));
66  EXPECT_EQ(1, (*iterator)(1));
67 
68  ++iterator;
69  EXPECT_FALSE(iterator.isPastEnd());
70  ++iterator;
71  EXPECT_FALSE(iterator.isPastEnd());
72  ++iterator;
73  EXPECT_TRUE(iterator.isPastEnd());
74 }
75 
76 TEST(LineIterator, StartAndEndOutsideMap)
77 {
78  GridMap map( { "types" });
79  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
80 
81  EXPECT_NO_THROW(LineIterator iterator(map, Position(-7.0, -9.0), Position(8.0, 8.0)));
82  LineIterator iterator(map, Position(-7.0, -9.0), Position(8.0, 8.0));
83 
84  EXPECT_FALSE(iterator.isPastEnd());
85  EXPECT_EQ(5, (*iterator)(0));
86  EXPECT_EQ(4, (*iterator)(1));
87 
88  ++iterator;
89  EXPECT_FALSE(iterator.isPastEnd());
90  EXPECT_EQ(4, (*iterator)(0));
91  EXPECT_EQ(3, (*iterator)(1));
92 
93  ++iterator;
94  EXPECT_FALSE(iterator.isPastEnd());
95  EXPECT_EQ(3, (*iterator)(0));
96  EXPECT_EQ(2, (*iterator)(1));
97 
98  ++iterator;
99  ++iterator;
100  ++iterator;
101  EXPECT_TRUE(iterator.isPastEnd());
102 }
103 
104 TEST(LineIterator, StartAndEndOutsideMapWithoutIntersectingMap)
105 {
106  GridMap map( { "types" });
107  map.setGeometry(Length(8.0, 5.0), 1.0, Position(0.0, 0.0));
108 
109  EXPECT_THROW(LineIterator iterator(map, Position(-8.0, 8.0), Position(8.0, 8.0)), std::invalid_argument);
110 }
111 
112 TEST(LineIterator, MovedMap)
113 {
114  GridMap map( { "types" });
115  map.setGeometry(Length(7.0, 5.0), 1.0, Position(0.0, 0.0));
116  map.move(Position(2.0, 2.0));
117 
118  EXPECT_NO_THROW(LineIterator iterator(map, Position(0.0, 0.0), Position(2.0, 2.0)));
119  LineIterator iterator(map, Position(0.0, 0.0), Position(2.0, 2.0));
120  Position point;
121 
122  EXPECT_FALSE(iterator.isPastEnd());
123  map.getPosition(*iterator, point);
124  EXPECT_EQ(0, point.x());
125  EXPECT_EQ(0, point.y());
126 
127  ++iterator;
128  EXPECT_FALSE(iterator.isPastEnd());
129  map.getPosition(*iterator, point);
130  EXPECT_EQ(1, point.x());
131  EXPECT_EQ(1, point.y());
132 
133  ++iterator;
134  EXPECT_FALSE(iterator.isPastEnd());
135  map.getPosition(*iterator, point);
136  EXPECT_EQ(2, point.x());
137  EXPECT_EQ(2, point.y());
138 
139  ++iterator;
140  EXPECT_TRUE(iterator.isPastEnd());
141 }
142 
143 TEST(LineIterator, StartAndEndOutsideMovedMap)
144 {
145  GridMap map( { "types" });
146  map.setGeometry(Length(7.0, 5.0), 1.0, Position(0.0, 0.0));
147  map.move(Position(2.0, 2.0));
148 
149  EXPECT_NO_THROW(LineIterator iterator(map, Position(0.0, 0.0), Position(8.0, 8.0)));
150  LineIterator iterator(map, Position(0.0, 0.0), Position(8.0, 8.0));
151  Position point;
152 
153  EXPECT_FALSE(iterator.isPastEnd());
154  map.getPosition(*iterator, point);
155  EXPECT_EQ(0, point.x());
156  EXPECT_EQ(0, point.y());
157 
158  ++iterator;
159  map.getPosition(*iterator, point);
160  EXPECT_EQ(1, point.x());
161  EXPECT_EQ(1, point.y());
162  //
163  ++iterator;
164  map.getPosition(*iterator, point);
165  EXPECT_EQ(2, point.x());
166  EXPECT_EQ(2, point.y());
167  //
168  ++iterator;
169  map.getPosition(*iterator, point);
170  EXPECT_EQ(3, point.x());
171  EXPECT_EQ(3, point.y());
172 
173  ++iterator;
174  map.getPosition(*iterator, point);
175  EXPECT_EQ(4, point.x());
176  EXPECT_EQ(4, point.y());
177 
178  ++iterator;
179  EXPECT_TRUE(iterator.isPastEnd());
180 }
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
Definition: GridMap.cpp:45
TEST(LineIterator, StartOutsideMap)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
bool isPastEnd() const


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 1 2021 02:13:27