forked from tier4/scenario_simulator_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_linear_algebra.cpp
95 lines (82 loc) · 2.71 KB
/
test_linear_algebra.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <geometry/linear_algebra.hpp>
#include "expect_eq_macros.hpp"
TEST(LINEAR_ALGEBRA, GET_SIZE)
{
geometry_msgs::msg::Vector3 vec;
EXPECT_DOUBLE_EQ(math::geometry::getSize(vec), 0.0);
vec.x = 1.0;
vec.y = 0.0;
vec.z = 3.0;
EXPECT_DOUBLE_EQ(math::geometry::getSize(vec), std::sqrt(10.0));
}
TEST(LINEAR_ALGEBRA, NORMALIZE)
{
geometry_msgs::msg::Vector3 vec;
EXPECT_THROW(math::geometry::normalize(vec), common::SimulationError);
vec.x = 1.0;
vec.y = 0.0;
vec.z = 3.0;
vec = math::geometry::normalize(vec);
EXPECT_DOUBLE_EQ(vec.x, 0.31622776601683794);
EXPECT_DOUBLE_EQ(vec.y, 0.0);
EXPECT_DOUBLE_EQ(vec.z, 0.94868329805051377);
EXPECT_DOUBLE_EQ(math::geometry::getSize(vec), 1.0);
}
TEST(LINEAR_ALGEBRA, MULTIPLY)
{
geometry_msgs::msg::Vector3 vec = math::geometry::vector3(0, 3, 1);
vec * 1.0;
EXPECT_VECTOR3_EQ((vec * 1.0), math::geometry::vector3(0, 3, 1));
EXPECT_VECTOR3_EQ((vec * 2.0), math::geometry::vector3(0, 6, 2));
EXPECT_VECTOR3_EQ((vec * 2.0), (2.0 * vec));
}
TEST(LINEAR_ALGEBRA, ADDITION)
{
geometry_msgs::msg::Vector3 vec = math::geometry::vector3(0, 3, 1);
EXPECT_VECTOR3_EQ((vec + vec), (2.0 * vec));
geometry_msgs::msg::Point p;
p.x = 0;
p.y = 3;
p.z = 1;
EXPECT_VECTOR3_EQ((p + vec), (2.0 * vec));
}
TEST(LINEAR_ALGEBRA, SUBTRACTION)
{
geometry_msgs::msg::Vector3 vec = math::geometry::vector3(0, 3, 1);
EXPECT_VECTOR3_EQ((vec - vec), geometry_msgs::msg::Vector3());
geometry_msgs::msg::Point p;
p.x = 0;
p.y = 3;
p.z = 1;
EXPECT_VECTOR3_EQ((p - vec), geometry_msgs::msg::Vector3());
}
TEST(LINEAR_ALGEBRA, EQUAL)
{
geometry_msgs::msg::Vector3 vec0 = math::geometry::vector3(0, 3, 1);
geometry_msgs::msg::Vector3 vec1 = math::geometry::vector3(0, 3, 1);
// This is fine usage of default ROS operator
EXPECT_TRUE(vec0.operator==(vec1));
// This is fine usage of custom operator (with machine epsilon)
EXPECT_TRUE(operator==(vec0, vec1));
// This is ambiguous and causes compilation error
EXPECT_TRUE(vec0 == vec1);
}
int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}