testUtilities.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 /*
13  * @file testUtilities.cpp
14  * @date Aug 19, 2021
15  * @author Varun Agrawal
16  * @brief Tests for the utilities.
17  */
18 
20 #include <gtsam/base/Testable.h>
21 #include <gtsam/geometry/Point2.h>
22 #include <gtsam/geometry/Pose3.h>
23 #include <gtsam/inference/Symbol.h>
25 
26 using namespace gtsam;
30 
31 /* ************************************************************************* */
32 TEST(Utilities, ExtractPoint2) {
33  Point2 p0(0, 0), p1(1, 0);
34  Values values;
35  values.insert<Point2>(L(0), p0);
36  values.insert<Point2>(L(1), p1);
37  values.insert<Rot3>(R(0), Rot3());
38  values.insert<Pose3>(X(0), Pose3());
39 
40  Matrix all_points = utilities::extractPoint2(values);
41  EXPECT_LONGS_EQUAL(2, all_points.rows());
42 }
43 
44 /* ************************************************************************* */
45 TEST(Utilities, ExtractPoint3) {
46  Point3 p0(0, 0, 0), p1(1, 0, 0);
47  Values values;
48  values.insert<Point3>(L(0), p0);
49  values.insert<Point3>(L(1), p1);
50  values.insert<Rot3>(R(0), Rot3());
51  values.insert<Pose3>(X(0), Pose3());
52 
53  Matrix all_points = utilities::extractPoint3(values);
54  EXPECT_LONGS_EQUAL(2, all_points.rows());
55 }
56 
57 /* ************************************************************************* */
58 TEST(Utilities, ExtractVector) {
59  // Test normal case with 3 vectors and 1 non-vector (ignore non-vector)
60  auto values = Values();
61  values.insert(X(0), (Vector(4) << 1, 2, 3, 4).finished());
62  values.insert(X(2), (Vector(4) << 13, 14, 15, 16).finished());
63  values.insert(X(1), (Vector(4) << 6, 7, 8, 9).finished());
64  values.insert(X(3), Pose3());
65  auto actual = utilities::extractVectors(values, 'x');
66  auto expected =
67  (Matrix(3, 4) << 1, 2, 3, 4, 6, 7, 8, 9, 13, 14, 15, 16).finished();
68  EXPECT(assert_equal(expected, actual));
69 
70  // Check that mis-sized vectors fail
71  values.insert(X(4), (Vector(2) << 1, 2).finished());
73  values.update(X(4), (Vector(6) << 1, 2, 3, 4, 5, 6).finished());
75 }
76 
77 /* ************************************************************************* */
78 int main() {
79  srand(time(nullptr));
80  TestResult tr;
81  return TestRegistry::runAllTests(tr);
82 }
83 /* ************************************************************************* */
int main()
Matrix extractVectors(const Values &values, char c)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Vector3f p1
Matrix expected
Definition: testMatrix.cpp:971
Vector2 Point2
Definition: Point2.h:32
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Rot2 R(Rot2::fromAngle(0.1))
leaf::MyValues values
void update(Key j, const Value &val)
Definition: Values.cpp:169
MatrixXd L
Definition: LLT_example.cpp:6
Vector3f p0
Key X(std::uint64_t j)
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
Matrix extractPoint2(const Values &values)
Extract all Point2 values into a single matrix [x y].
Eigen::VectorXd Vector
Definition: Vector.h:38
#define THROWS_EXCEPTION(condition)
Definition: Test.h:112
#define EXPECT(condition)
Definition: Test.h:150
#define time
traits
Definition: chartTesting.h:28
std::vector< float > Values
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
Key R(std::uint64_t j)
Key L(std::uint64_t j)
void insert(Key j, const Value &val)
Definition: Values.cpp:155
Vector3 Point3
Definition: Point3.h:38
TEST(SmartFactorBase, Pinhole)
#define X
Definition: icosphere.cpp:20
2D Point
3D Pose
Matrix extractPoint3(const Values &values)
Extract all Point3 values into a single matrix [x y z].


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:56