GridMapIteratorTest.cpp
Go to the documentation of this file.
00001 /*
00002  * GridMapDataIterator.cpp
00003  *
00004  *  Created on: Feb 16, 2016
00005  *      Author: Péter Fankhauser
00006  *       Institute: ETH Zurich, ANYbotics
00007  */
00008 
00009 #include "grid_map_core/iterators/GridMapIterator.hpp"
00010 #include "grid_map_core/GridMap.hpp"
00011 
00012 // Eigen
00013 #include <Eigen/Core>
00014 
00015 // gtest
00016 #include <gtest/gtest.h>
00017 
00018 // Limits
00019 #include <cfloat>
00020 
00021 // Vector
00022 #include <vector>
00023 
00024 using namespace std;
00025 using namespace grid_map;
00026 
00027 TEST(GridMapIterator, Simple)
00028 {
00029   GridMap map;
00030   map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
00031   map.add("layer", 0.0);
00032   GridMapIterator iterator(map);
00033 
00034   unsigned int i = 0;
00035   for (; !iterator.isPastEnd(); ++iterator, ++i) {
00036     map.at("layer", *iterator) = 1.0;
00037     EXPECT_FALSE(iterator.isPastEnd());
00038   }
00039 
00040   EXPECT_EQ(40, i);
00041   EXPECT_TRUE(iterator.isPastEnd());
00042   EXPECT_TRUE((map["layer"].array() == 1.0f).all());
00043 }
00044 
00045 TEST(GridMapIterator, LinearIndex)
00046 {
00047   GridMap map;
00048   map.setGeometry(Length(8.1, 5.1), 1.0, Position(0.0, 0.0)); // bufferSize(8, 5)
00049   map.add("layer", 0.0);
00050   GridMapIterator iterator(map);
00051 
00052   auto& data = map["layer"];
00053   unsigned int i = 0;
00054   for (; !iterator.isPastEnd(); ++iterator, ++i) {
00055     data(iterator.getLinearIndex()) = 1.0;
00056     EXPECT_EQ(i, iterator.getLinearIndex());
00057     EXPECT_FALSE(iterator.isPastEnd());
00058   }
00059 
00060   EXPECT_EQ(40, i);
00061   EXPECT_TRUE(iterator.isPastEnd());
00062   EXPECT_TRUE((map["layer"].array() == 1.0f).all());
00063 }


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jul 9 2019 05:06:13