bounds_test.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #include <gtest/gtest.h>
35 #include <nav_core2/bounds.h>
36 
37 using nav_core2::Bounds;
39 
40 TEST(Bounds, test_bounds_simple)
41 {
42  Bounds b;
43  EXPECT_TRUE(b.isEmpty());
44 
45  b.touch(5.0, 6.0);
46  EXPECT_EQ(5.0, b.getMinX());
47  EXPECT_EQ(5.0, b.getMinX());
48  EXPECT_EQ(5.0, b.getMaxX());
49  EXPECT_EQ(6.0, b.getMinY());
50  EXPECT_EQ(6.0, b.getMaxY());
51  EXPECT_TRUE(b.contains(5.0, 6.0));
52  EXPECT_FALSE(b.contains(5.5, 6.0));
53  EXPECT_FALSE(b.contains(5.5, 4.0));
54  EXPECT_FALSE(b.isEmpty());
55 
56  Bounds b2 = b;
57  EXPECT_EQ(5.0, b2.getMinX());
58  EXPECT_EQ(5.0, b2.getMaxX());
59  EXPECT_EQ(6.0, b2.getMinY());
60  EXPECT_EQ(6.0, b2.getMaxY());
61 
62  b.reset();
63  EXPECT_EQ(5.0, b2.getMinX());
64  EXPECT_EQ(5.0, b2.getMaxX());
65  EXPECT_EQ(6.0, b2.getMinY());
66  EXPECT_EQ(6.0, b2.getMaxY());
67  EXPECT_FALSE(b.contains(5.0, 6.0));
68  EXPECT_FALSE(b.contains(5.5, 6.0));
69  EXPECT_TRUE(b2.contains(5.0, 6.0));
70  EXPECT_FALSE(b.contains(5.5, 6.0));
71  EXPECT_TRUE(b.isEmpty());
72 
73  Bounds b3;
74  b3.touch(1.0, 5.0);
75  b3.touch(4.0, 2.0);
76  EXPECT_TRUE(b3.contains(3.0, 3.0));
77  EXPECT_FALSE(b3.contains(0.0, 3.0));
78  EXPECT_FALSE(b3.contains(5.0, 3.0));
79  EXPECT_FALSE(b3.contains(3.0, 6.0));
80  EXPECT_FALSE(b3.contains(3.0, 1.0));
81 }
82 
83 TEST(Bounds, test_dimensions)
84 {
85  UIntBounds empty;
86  UIntBounds square(0, 0, 5, 5);
87  UIntBounds rectangle(1, 4, 3, 15);
88  EXPECT_EQ(empty.getWidth(), 0u);
89  EXPECT_EQ(empty.getHeight(), 0u);
90 
91  EXPECT_EQ(square.getWidth(), 6u);
92  EXPECT_EQ(square.getHeight(), 6u);
93 
94  EXPECT_EQ(rectangle.getWidth(), 3u);
95  EXPECT_EQ(rectangle.getHeight(), 12u);
96 }
97 
98 TEST(Bounds, test_bounds_overlap)
99 {
100  UIntBounds b0(0, 0, 5, 5);
101  UIntBounds b1(0, 0, 5, 5);
102  UIntBounds b2(0, 0, 3, 3);
103  UIntBounds b3(3, 0, 4, 4);
104  UIntBounds b4(4, 0, 4, 4);
105  UIntBounds b5(1, 4, 3, 15);
106  UIntBounds b6(10, 10, 10, 10);
107  EXPECT_TRUE(b0.overlaps(b0));
108  EXPECT_TRUE(b0.overlaps(b1));
109  EXPECT_TRUE(b0.overlaps(b2));
110  EXPECT_TRUE(b2.overlaps(b0));
111  EXPECT_TRUE(b0.overlaps(b3));
112  EXPECT_TRUE(b2.overlaps(b3));
113  EXPECT_FALSE(b2.overlaps(b4));
114  EXPECT_TRUE(b0.overlaps(b5));
115  EXPECT_TRUE(b5.overlaps(b0));
116  EXPECT_FALSE(b0.overlaps(b6));
117  EXPECT_FALSE(b6.overlaps(b0));
118 }
119 
120 int main(int argc, char **argv)
121 {
122  testing::InitGoogleTest(&argc, argv);
123  return RUN_ALL_TESTS();
124 }
bool overlaps(const GenericBounds< NumericType > &other) const
returns true if the two bounds overlap each other
Definition: bounds.h:146
GenericBounds< double > Bounds
Definition: bounds.h:192
TEST(Bounds, test_bounds_simple)
Definition: bounds_test.cpp:40
int main(int argc, char **argv)
unsigned int getHeight() const
Definition: bounds.h:204
unsigned int getWidth() const
Definition: bounds.h:203


nav_core2
Author(s):
autogenerated on Sun Jan 10 2021 04:08:27