testHybridValues.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 
18 #include <gtsam/base/Testable.h>
24 #include <gtsam/inference/Key.h>
25 #include <gtsam/inference/Symbol.h>
27 #include <gtsam/nonlinear/Values.h>
28 
29 // Include for test suite
31 
32 using namespace std;
33 using namespace gtsam;
34 
35 static const HybridValues kExample{{{99, Vector2(2, 3)}}, {{100, 3}}};
36 
37 /* ************************************************************************* */
38 TEST(HybridValues, Basics) {
40  values.insert(99, Vector2(2, 3));
41  values.insert(100, 3);
42  EXPECT(assert_equal(kExample, values));
43  EXPECT(assert_equal(values.at(99), Vector2(2, 3)));
44  EXPECT(assert_equal(values.atDiscrete(100), int(3)));
45 
46  HybridValues values2;
47  values2.insert(100, 3);
48  values2.insert(99, Vector2(2, 3));
49  EXPECT(assert_equal(kExample, values2));
50 }
51 
52 /* ************************************************************************* */
53 // Check insert
54 TEST(HybridValues, Insert) {
55  HybridValues actual;
56  EXPECT(assert_equal({{}, {{100, 3}}}, //
57  actual.insert(DiscreteValues{{100, 3}})));
59  actual.insert(VectorValues{{99, Vector2(2, 3)}})));
60  HybridValues actual2;
62 }
63 
64 /* ************************************************************************* */
65 // Check update.
66 TEST(HybridValues, Update) {
67  HybridValues actual(kExample);
68  EXPECT(assert_equal({{{99, Vector2(2, 3)}}, {{100, 2}}},
69  actual.update(DiscreteValues{{100, 2}})));
70  EXPECT(assert_equal({{{99, Vector1(4)}}, {{100, 2}}},
71  actual.update(VectorValues{{99, Vector1(4)}})));
72  HybridValues actual2(kExample);
74 }
75 
76 /* ************************************************************************* */
77 int main() {
78  TestResult tr;
79  return TestRegistry::runAllTests(tr);
80 }
81 /* ************************************************************************* */
Provides additional testing facilities for common data structures.
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
A non-templated config holding any types of Manifold-group elements.
Eigen::Matrix< double, 1, 1 > Vector1
Definition: testEvent.cpp:33
An assignment from labels to a discrete value index (size_t)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
TEST(HybridValues, Basics)
leaf::MyValues values
Definition: BFloat16.h:88
static const HybridValues kExample
int main()
HybridValues & update(const VectorValues &values)
Definition: HybridValues.h:181
Factor Graph Values.
#define EXPECT(condition)
Definition: Test.h:150
traits
Definition: chartTesting.h:28
specialized key for discrete variables
Eigen::Vector2d Vector2
Definition: Vector.h:42
void insert(Key j, const Vector &value)
Definition: HybridValues.h:117
Vector & at(Key j)
Definition: HybridValues.h:169
size_t & atDiscrete(Key j)
Definition: HybridValues.h:175


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:23