test_linear_grid.cpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
17 #include <cstddef>
18 #include <optional>
19 #include <vector>
20 
22 
23 namespace {
24 
25 TEST(LinearGrid2, InvalidSize) {
26  constexpr std::size_t kWidth = 4;
27  ASSERT_DEBUG_DEATH(beluga::ValueGrid2<bool>({{true, false, true, false, false}}, kWidth), "Assertion");
28 }
29 
30 TEST(LinearGrid2, Indices) {
31  constexpr std::size_t kWidth = 4;
32  const auto grid = beluga::ValueGrid2<bool>{{{true, false, true, false, false, true, false, true}}, kWidth};
33 
34  EXPECT_EQ(grid.index_at(0, 0), 0);
35  EXPECT_EQ(grid.index_at(3, 1), 7);
36 
37  EXPECT_EQ(grid.index_at(Eigen::Vector2i(0, 0)), 0);
38  EXPECT_EQ(grid.index_at(Eigen::Vector2i(3, 1)), 7);
39 }
40 
41 TEST(LinearGrid2, CoordinatesAtIndex) {
42  constexpr std::size_t kWidth = 4;
43  constexpr std::size_t kResolution = 1;
44  const auto grid =
45  beluga::ValueGrid2<bool>{{{true, false, true, false, false, true, false, true}}, kWidth, kResolution};
46 
47  EXPECT_EQ(grid.coordinates_at(0), Eigen::Vector2d(0.5, 0.5));
48  EXPECT_EQ(grid.coordinates_at(3), Eigen::Vector2d(3.5, 0.5));
49  EXPECT_EQ(grid.coordinates_at(5), Eigen::Vector2d(1.5, 1.5));
50 }
51 
52 TEST(LinearGrid2, DataAtIndex) {
53  constexpr std::size_t kWidth = 4;
54  constexpr std::size_t kResolution = 1;
55  const auto grid =
56  beluga::ValueGrid2<bool>{{{true, false, true, false, false, true, false, true}}, kWidth, kResolution};
57 
58  EXPECT_TRUE(grid.data_at(0).value());
59  EXPECT_FALSE(grid.data_at(3).value());
60  EXPECT_TRUE(grid.data_at(5).value());
61  EXPECT_EQ(grid.data_at(10), std::nullopt);
62 }
63 
64 } // namespace
value_grid.hpp
Implementation of generic value grid.
beluga::ValueGrid2
Generic 2D linear value grid.
Definition: value_grid.hpp:36
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53