test_blockmem_gridmap.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 #include <limits>
00032 
00033 #include <gtest/gtest.h>
00034 
00035 #include <planner_cspace/blockmem_gridmap.h>
00036 
00037 TEST(BlockmemGridmap, ResetClear)
00038 {
00039   BlockMemGridmap<float, 3, 3, 0x20> gm;
00040 
00041   for (int s = 4; s <= 6; s += 2)
00042   {
00043     gm.reset(CyclicVecInt<3, 3>(s, s, s));
00044     gm.clear(0.0);
00045 
00046     CyclicVecInt<3, 3> i;
00047     for (i[0] = 0; i[0] < s; ++i[0])
00048     {
00049       for (i[1] = 0; i[1] < s; ++i[1])
00050       {
00051         for (i[2] = 0; i[2] < s; ++i[2])
00052         {
00053           ASSERT_EQ(gm[i], 0.0);
00054         }
00055       }
00056     }
00057 
00058     gm.clear(3.0);
00059     for (i[0] = 0; i[0] < s; ++i[0])
00060     {
00061       for (i[1] = 0; i[1] < s; ++i[1])
00062       {
00063         for (i[2] = 0; i[2] < s; ++i[2])
00064         {
00065           ASSERT_EQ(gm[i], 3.0);
00066         }
00067       }
00068     }
00069   }
00070 }
00071 
00072 TEST(BlockmemGridmap, WriteRead)
00073 {
00074   BlockMemGridmap<float, 3, 3, 0x20> gm;
00075 
00076   const int s = 4;
00077   gm.reset(CyclicVecInt<3, 3>(s, s, s));
00078   gm.clear(0.0);
00079 
00080   CyclicVecInt<3, 3> i;
00081   for (i[0] = 0; i[0] < s; ++i[0])
00082   {
00083     for (i[1] = 0; i[1] < s; ++i[1])
00084     {
00085       for (i[2] = 0; i[2] < s; ++i[2])
00086       {
00087         gm[i] = i[2] * 100 + i[1] * 10 + i[0];
00088       }
00089     }
00090   }
00091 
00092   for (i[0] = 0; i[0] < s; ++i[0])
00093   {
00094     for (i[1] = 0; i[1] < s; ++i[1])
00095     {
00096       for (i[2] = 0; i[2] < s; ++i[2])
00097       {
00098         ASSERT_EQ(gm[i], i[2] * 100 + i[1] * 10 + i[0]);
00099       }
00100     }
00101   }
00102 }
00103 
00104 TEST(BlockmemGridmap, OuterBoundery)
00105 {
00106   BlockMemGridmap<float, 3, 2, 0x20> gm;
00107 
00108   const int s = 0x30;
00109   gm.reset(CyclicVecInt<3, 2>(s, s, s));
00110   gm.clear(1.0);
00111 
00112   CyclicVecInt<3, 2> i;
00113   const int outer = 0x10;
00114   for (i[0] = -outer; i[0] < s + outer; ++i[0])
00115   {
00116     for (i[1] = -outer; i[1] < s + outer; ++i[1])
00117     {
00118       for (i[2] = -outer; i[2] < s + outer; ++i[2])
00119       {
00120         if (i[0] >= 0 && i[1] >= 0 && i[2] >= 0 &&
00121             i[0] < s && i[1] < s && i[2] < s)
00122         {
00123           ASSERT_TRUE(gm.validate(i));
00124         }
00125         else
00126         {
00127           ASSERT_FALSE(gm.validate(i));
00128         }
00129         // Confirm at least not dead
00130         gm[i] = 1.0;
00131       }
00132     }
00133   }
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