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


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:13