test_cyclic_vec.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <cmath>
31 #include <cstddef>
32 
34 
35 #include <gtest/gtest.h>
36 
37 namespace planner_cspace
38 {
39 TEST(CyclicVec, InitFloat)
40 {
41  const float val[3] = {1.0, 2.0, 3.0};
42  CyclicVecFloat<3, 2> v(1.0f, 2.0f, 3.0f);
43  const CyclicVecFloat<3, 2> vc(1.0f, 2.0f, 3.0f);
44 
45  for (size_t i = 0; i < 3; ++i)
46  {
47  ASSERT_EQ(v[i], val[i]);
48  ASSERT_EQ(vc[i], val[i]);
49  }
50 }
51 
52 TEST(CyclicVec, InitInt)
53 {
54  const int val[3] = {1, 2, 3};
55  CyclicVecInt<3, 2> v(1, 2, 3);
56  const CyclicVecInt<3, 2> vc(1, 2, 3);
57 
58  for (size_t i = 0; i < 3; ++i)
59  {
60  ASSERT_EQ(v[i], val[i]);
61  ASSERT_EQ(vc[i], val[i]);
62  }
63 }
64 
65 TEST(CyclicVec, OperatorsFloat)
66 {
67  using Vec3 = CyclicVecFloat<3, 2>;
68  Vec3 v1(1.0f, 2.0f, 3.0f);
69  Vec3 v12(1.0f, 2.0f, 3.0f);
70  Vec3 v2(4.0f, 5.0f, 6.0f);
71 
72  ASSERT_EQ(v1, v12);
73  ASSERT_NE(v1, v2);
74  ASSERT_NE(v12, v2);
75 
76  ASSERT_EQ(v1 + v2, Vec3(5.0f, 7.0f, 9.0f));
77  ASSERT_EQ(v1 - v2, Vec3(-3.0f, -3.0f, -3.0f));
78  ASSERT_EQ(v1 * v2, Vec3(4.0f, 10.0f, 18.0f));
79 }
80 
81 TEST(CyclicVec, OperatorsInt)
82 {
83  using Vec3 = CyclicVecInt<3, 2>;
84  Vec3 v1(1, 2, 3);
85  Vec3 v12(1, 2, 3);
86  Vec3 v2(4, 5, 6);
87 
88  ASSERT_EQ(v1, v12);
89  ASSERT_NE(v1, v2);
90  ASSERT_NE(v12, v2);
91 
92  ASSERT_EQ(v1 + v2, Vec3(5, 7, 9));
93  ASSERT_EQ(v1 - v2, Vec3(-3, -3, -3));
94  ASSERT_EQ(v1 * v2, Vec3(4, 10, 18));
95 }
96 
97 TEST(CyclicVec, LengthInt)
98 {
99  using Vec3 = CyclicVecInt<3, 2>;
100  Vec3 v(3, 4, 5);
101 
102  ASSERT_EQ(v.sqlen(), 25);
103  ASSERT_EQ(v.len(), 5.0);
104  ASSERT_EQ(v.norm(), std::sqrt(50.0f));
105 }
106 
107 TEST(CyclicVec, LengthFloat)
108 {
109  using Vec3 = CyclicVecFloat<3, 2>;
110  Vec3 v(3.0f, 4.0f, 5.0f);
111 
112  ASSERT_EQ(v.sqlen(), 25.0);
113  ASSERT_EQ(v.len(), 5.0);
114  ASSERT_EQ(v.norm(), std::sqrt(50.0f));
115 }
116 
117 TEST(CyclicVec, Cycle)
118 {
119  using Vec3 = CyclicVecInt<3, 2>;
120  Vec3 v(3, 4, 5);
121  v.cycle(4);
122  ASSERT_EQ(v[2], 1);
123  v.cycleUnsigned(4);
124  ASSERT_EQ(v[2], 1);
125 
126  v[2] = 7;
127  v.cycle(4);
128  ASSERT_EQ(v[2], -1);
129  v.cycleUnsigned(4);
130  ASSERT_EQ(v[2], 3);
131 }
132 } // namespace planner_cspace
133 
134 int main(int argc, char** argv)
135 {
136  testing::InitGoogleTest(&argc, argv);
137 
138  return RUN_ALL_TESTS();
139 }
TEST(BlockmemGridmap, BlockWidth)
f
int main(int argc, char **argv)


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 3 2023 02:39:06