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] =
42  {
43  1.0, 2.0, 3.0
44  };
45  CyclicVecFloat<3, 2> v(1.0f, 2.0f, 3.0f);
46  const CyclicVecFloat<3, 2> vc(1.0f, 2.0f, 3.0f);
47 
48  for (size_t i = 0; i < 3; ++i)
49  {
50  ASSERT_EQ(v[i], val[i]);
51  ASSERT_EQ(vc[i], val[i]);
52  }
53 }
54 
55 TEST(CyclicVec, InitInt)
56 {
57  const int val[3] =
58  {
59  1, 2, 3
60  };
61  CyclicVecInt<3, 2> v(1, 2, 3);
62  const CyclicVecInt<3, 2> vc(1, 2, 3);
63 
64  for (size_t i = 0; i < 3; ++i)
65  {
66  ASSERT_EQ(v[i], val[i]);
67  ASSERT_EQ(vc[i], val[i]);
68  }
69 }
70 
71 TEST(CyclicVec, OperatorsFloat)
72 {
73  using Vec3 = CyclicVecFloat<3, 2>;
74  Vec3 v1(1.0f, 2.0f, 3.0f);
75  Vec3 v12(1.0f, 2.0f, 3.0f);
76  Vec3 v2(4.0f, 5.0f, 6.0f);
77 
78  ASSERT_EQ(v1, v12);
79  ASSERT_NE(v1, v2);
80  ASSERT_NE(v12, v2);
81 
82  ASSERT_EQ(v1 + v2, Vec3(5.0f, 7.0f, 9.0f));
83  ASSERT_EQ(v1 - v2, Vec3(-3.0f, -3.0f, -3.0f));
84  ASSERT_EQ(v1 * v2, Vec3(4.0f, 10.0f, 18.0f));
85 }
86 
87 TEST(CyclicVec, OperatorsInt)
88 {
89  using Vec3 = CyclicVecInt<3, 2>;
90  Vec3 v1(1, 2, 3);
91  Vec3 v12(1, 2, 3);
92  Vec3 v2(4, 5, 6);
93 
94  ASSERT_EQ(v1, v12);
95  ASSERT_NE(v1, v2);
96  ASSERT_NE(v12, v2);
97 
98  ASSERT_EQ(v1 + v2, Vec3(5, 7, 9));
99  ASSERT_EQ(v1 - v2, Vec3(-3, -3, -3));
100  ASSERT_EQ(v1 * v2, Vec3(4, 10, 18));
101 }
102 
103 TEST(CyclicVec, LengthInt)
104 {
105  using Vec3 = CyclicVecInt<3, 2>;
106  Vec3 v(3, 4, 5);
107 
108  ASSERT_EQ(v.sqlen(), 25);
109  ASSERT_EQ(v.len(), 5.0);
110  ASSERT_EQ(v.norm(), std::sqrt(50.0f));
111 }
112 
113 TEST(CyclicVec, LengthFloat)
114 {
115  using Vec3 = CyclicVecFloat<3, 2>;
116  Vec3 v(3.0f, 4.0f, 5.0f);
117 
118  ASSERT_EQ(v.sqlen(), 25.0);
119  ASSERT_EQ(v.len(), 5.0);
120  ASSERT_EQ(v.norm(), std::sqrt(50.0f));
121 }
122 
123 TEST(CyclicVec, Cycle)
124 {
125  using Vec3 = CyclicVecInt<3, 2>;
126  Vec3 v(3, 4, 5);
127  v.cycle(4);
128  ASSERT_EQ(v[2], 1);
129  v.cycleUnsigned(4);
130  ASSERT_EQ(v[2], 1);
131 
132  v[2] = 7;
133  v.cycle(4);
134  ASSERT_EQ(v[2], -1);
135  v.cycleUnsigned(4);
136  ASSERT_EQ(v[2], 3);
137 }
138 } // namespace planner_cspace
139 
140 int main(int argc, char** argv)
141 {
142  testing::InitGoogleTest(&argc, argv);
143 
144  return RUN_ALL_TESTS();
145 }
TEST(BlockmemGridmap, BlockWidth)
f
int main(int argc, char **argv)


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:42