test_cyclic_vec.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2017, the neonavigation authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <cstddef>
00031 
00032 #include <gtest/gtest.h>
00033 
00034 #include <planner_cspace/cyclic_vec.h>
00035 
00036 TEST(CyclicVec, InitFloat)
00037 {
00038   const float val[3] =
00039       {
00040         1.0, 2.0, 3.0
00041       };
00042   CyclicVecFloat<3, 2> v(1.0f, 2.0f, 3.0f);
00043   const CyclicVecFloat<3, 2> vc(1.0f, 2.0f, 3.0f);
00044 
00045   for (size_t i = 0; i < 3; ++i)
00046   {
00047     ASSERT_EQ(v[i], val[i]);
00048     ASSERT_EQ(vc[i], val[i]);
00049   }
00050 }
00051 
00052 TEST(CyclicVec, InitInt)
00053 {
00054   const int val[3] =
00055       {
00056         1, 2, 3
00057       };
00058   CyclicVecInt<3, 2> v(1, 2, 3);
00059   const CyclicVecInt<3, 2> vc(1, 2, 3);
00060 
00061   for (size_t i = 0; i < 3; ++i)
00062   {
00063     ASSERT_EQ(v[i], val[i]);
00064     ASSERT_EQ(vc[i], val[i]);
00065   }
00066 }
00067 
00068 TEST(CyclicVec, OperatorsFloat)
00069 {
00070   using Vec3 = CyclicVecFloat<3, 2>;
00071   Vec3 v1(1.0f, 2.0f, 3.0f);
00072   Vec3 v12(1.0f, 2.0f, 3.0f);
00073   Vec3 v2(4.0f, 5.0f, 6.0f);
00074 
00075   ASSERT_EQ(v1, v12);
00076   ASSERT_NE(v1, v2);
00077   ASSERT_NE(v12, v2);
00078 
00079   ASSERT_EQ(v1 + v2, Vec3(5.0f, 7.0f, 9.0f));
00080   ASSERT_EQ(v1 - v2, Vec3(-3.0f, -3.0f, -3.0f));
00081   ASSERT_EQ(v1 * v2, Vec3(4.0f, 10.0f, 18.0f));
00082 }
00083 
00084 TEST(CyclicVec, OperatorsInt)
00085 {
00086   using Vec3 = CyclicVecInt<3, 2>;
00087   Vec3 v1(1, 2, 3);
00088   Vec3 v12(1, 2, 3);
00089   Vec3 v2(4, 5, 6);
00090 
00091   ASSERT_EQ(v1, v12);
00092   ASSERT_NE(v1, v2);
00093   ASSERT_NE(v12, v2);
00094 
00095   ASSERT_EQ(v1 + v2, Vec3(5, 7, 9));
00096   ASSERT_EQ(v1 - v2, Vec3(-3, -3, -3));
00097   ASSERT_EQ(v1 * v2, Vec3(4, 10, 18));
00098 }
00099 
00100 TEST(CyclicVec, LengthInt)
00101 {
00102   using Vec3 = CyclicVecInt<3, 2>;
00103   Vec3 v(3, 4, 5);
00104 
00105   ASSERT_EQ(v.sqlen(), 25);
00106   ASSERT_EQ(v.len(), 5.0);
00107   ASSERT_EQ(v.norm(), sqrtf(50));
00108 }
00109 
00110 TEST(CyclicVec, LengthFloat)
00111 {
00112   using Vec3 = CyclicVecFloat<3, 2>;
00113   Vec3 v(3.0f, 4.0f, 5.0f);
00114 
00115   ASSERT_EQ(v.sqlen(), 25.0);
00116   ASSERT_EQ(v.len(), 5.0);
00117   ASSERT_EQ(v.norm(), sqrtf(50.0));
00118 }
00119 
00120 TEST(CyclicVec, Cycle)
00121 {
00122   using Vec3 = CyclicVecInt<3, 2>;
00123   Vec3 v(3, 4, 5);
00124   v.cycle(4);
00125   ASSERT_EQ(v[2], 1);
00126   v.cycleUnsigned(4);
00127   ASSERT_EQ(v[2], 1);
00128 
00129   v[2] = 7;
00130   v.cycle(4);
00131   ASSERT_EQ(v[2], -1);
00132   v.cycleUnsigned(4);
00133   ASSERT_EQ(v[2], 3);
00134 }
00135 
00136 int main(int argc, char** argv)
00137 {
00138   testing::InitGoogleTest(&argc, argv);
00139 
00140   return RUN_ALL_TESTS();
00141 }


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 22 2019 20:07:27