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 
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
TestVector3
FixedVector< 3 > TestVector3
Definition: testFixedVector.cpp:24
gtsam::FixedVector::ones
static FixedVector ones()
Definition: FixedVector.h:83
gtsam::FixedVector
Definition: FixedVector.h:30
gtsam::FixedVector::repeat
static FixedVector repeat(double value)
Definition: FixedVector.h:52
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::vec3
static Vector9 vec3(const Matrix3 &R)
Definition: SO3.cpp:342
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::FixedVector::delta
static FixedVector delta(size_t i, double value)
Definition: FixedVector.h:63
gtsam::FixedVector::zero
static FixedVector zero()
Definition: FixedVector.h:78
main
int main()
Definition: testFixedVector.cpp:85
gtsam::vec4
static SO4::VectorN2 vec4(const Matrix4 &Q)
Definition: SO4.cpp:140
FixedVector.h
Extension of boost's bounded_vector to allow for fixed size operation.
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
gtsam::equals
Definition: Testable.h:112
TestResult
Definition: TestResult.h:26
gtsam
traits
Definition: SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
TestVector5
FixedVector< 5 > TestVector5
Definition: testFixedVector.cpp:23
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::FixedVector::basis
static FixedVector basis(size_t i)
Definition: FixedVector.h:73
vec1
RowVectorXd vec1(3)
v1
Vector v1
Definition: testSerializationBase.cpp:38


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:26