testFixedVector.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 
20 
21 using namespace gtsam;
22 
25 
26 static const double tol = 1e-9;
27 
28 /* ************************************************************************* */
29 TEST( testFixedVector, conversions ) {
30  double data1[] = {1.0, 2.0, 3.0};
31  Vector v1 = (Vector(3) << data1[0], data1[1], data1[2]).finished();
32  TestVector3 fv1(v1), fv2(data1);
33 
34  Vector actFv2(fv2);
35  EXPECT(assert_equal(v1, actFv2));
36 }
37 
38 /* ************************************************************************* */
39 TEST( testFixedVector, variable_constructor ) {
40  TestVector3 act(Vector3(1.0, 2.0, 3.0));
41  EXPECT_DOUBLES_EQUAL(1.0, act(0), tol);
42  EXPECT_DOUBLES_EQUAL(2.0, act(1), tol);
43  EXPECT_DOUBLES_EQUAL(3.0, act(2), tol);
44 }
45 
46 /* ************************************************************************* */
47 TEST( testFixedVector, equals ) {
48  TestVector3 vec1(Vector3(1.0, 2.0, 3.0)), vec2(Vector3(1.0, 2.0, 3.0)),
49  vec3(Vector3(2.0, 3.0, 4.0));
50  TestVector5 vec4((Vector(5) << 1.0, 2.0, 3.0, 4.0, 5.0).finished());
51 
53  EXPECT(assert_equal(vec1, vec2, tol));
54  EXPECT(assert_equal(vec2, vec1, tol));
55  EXPECT(!vec1.equals(vec3, tol));
56  EXPECT(!vec3.equals(vec1, tol));
57  EXPECT(!vec1.equals(vec4, tol));
58  EXPECT(!vec4.equals(vec1, tol));
59 }
60 
61 /* ************************************************************************* */
62 TEST( testFixedVector, static_constructors ) {
63  TestVector3 actZero = TestVector3::zero();
64  TestVector3 expZero(Vector3(0.0, 0.0, 0.0));
65  EXPECT(assert_equal(expZero, actZero, tol));
66 
67  TestVector3 actOnes = TestVector3::ones();
68  TestVector3 expOnes(Vector3(1.0, 1.0, 1.0));
69  EXPECT(assert_equal(expOnes, actOnes, tol));
70 
71  TestVector3 actRepeat = TestVector3::repeat(2.3);
72  TestVector3 expRepeat(Vector3(2.3, 2.3, 2.3));
73  EXPECT(assert_equal(expRepeat, actRepeat, tol));
74 
75  TestVector3 actBasis = TestVector3::basis(1);
76  TestVector3 expBasis(Vector3(0.0, 1.0, 0.0));
77  EXPECT(assert_equal(expBasis, actBasis, tol));
78 
79  TestVector3 actDelta = TestVector3::delta(1, 2.3);
80  TestVector3 expDelta(Vector3(0.0, 2.3, 0.0));
81  EXPECT(assert_equal(expDelta, actDelta, tol));
82 }
83 
84 /* ************************************************************************* */
85 int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
86 /* ************************************************************************* */
87 
88 
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
bool equals(const FixedVector< M > &other, double tol=1e-9) const
Definition: FixedVector.h:90
Vector v1
static FixedVector ones()
Definition: FixedVector.h:83
static FixedVector repeat(double value)
Definition: FixedVector.h:52
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:162
int main()
Eigen::VectorXd Vector
Definition: Vector.h:38
#define EXPECT(condition)
Definition: Test.h:151
Array< double, 1, 3 > e(1./3., 0.5, 2.)
FixedVector< 5 > TestVector5
static SO4::VectorN2 vec4(const Matrix4 &Q)
Definition: SO4.cpp:140
FixedVector< 3 > TestVector3
Extension of boost&#39;s bounded_vector to allow for fixed size operation.
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
RowVectorXd vec1(3)
TEST(LPInitSolver, InfiniteLoopSingleVar)
static Vector9 vec3(const Matrix3 &R)
Definition: SO3.cpp:307
const G double tol
Definition: Group.h:83
static FixedVector basis(size_t i)
Definition: FixedVector.h:73
static FixedVector zero()
Definition: FixedVector.h:78
static FixedVector delta(size_t i, double value)
Definition: FixedVector.h:63


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:35