From a7370818fad722ea6768a135c4d8c18f8552fe35 Mon Sep 17 00:00:00 2001 From: dellaert Date: Thu, 19 Feb 2015 10:54:55 +0100 Subject: [PATCH] Added unit test for SmartFactorBase (which immediatly exposed dim bug!) --- .cproject | 8 +++ gtsam/slam/tests/testSmartFactorBase.cpp | 72 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 gtsam/slam/tests/testSmartFactorBase.cpp diff --git a/.cproject b/.cproject index f3f62e42d..0bef605c5 100644 --- a/.cproject +++ b/.cproject @@ -1546,6 +1546,14 @@ true true + + make + -j4 + testSmartFactorBase.run + true + true + true + make -j3 diff --git a/gtsam/slam/tests/testSmartFactorBase.cpp b/gtsam/slam/tests/testSmartFactorBase.cpp new file mode 100644 index 000000000..618644981 --- /dev/null +++ b/gtsam/slam/tests/testSmartFactorBase.cpp @@ -0,0 +1,72 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file testSmartFactorBase.cpp + * @brief Unit tests for testSmartFactorBase Class + * @author Frank Dellaert + * @date Feb 2015 + */ + +#include "../SmartFactorBase.h" +#include +#include + +using namespace std; +using namespace gtsam; + +/* ************************************************************************* */ +#include +#include +class PinholeFactor: public SmartFactorBase, 9> { + virtual double error(const Values& values) const { + return 0.0; + } + virtual boost::shared_ptr linearize( + const Values& values) const { + return boost::shared_ptr(new JacobianFactor()); + } +}; + +TEST(SmartFactorBase, Pinhole) { + PinholeFactor f; + f.add(Point2(),1,SharedNoiseModel()); + f.add(Point2(),2,SharedNoiseModel()); + EXPECT_LONGS_EQUAL(2*2,f.dim()); +} + +/* ************************************************************************* */ +#include +class StereoFactor: public SmartFactorBase { + virtual double error(const Values& values) const { + return 0.0; + } + virtual boost::shared_ptr linearize( + const Values& values) const { + return boost::shared_ptr(new JacobianFactor()); + } +}; + +TEST(SmartFactorBase, Stereo) { + StereoFactor f; + f.add(StereoPoint2(),1,SharedNoiseModel()); + f.add(StereoPoint2(),2,SharedNoiseModel()); + EXPECT_LONGS_EQUAL(2*3,f.dim()); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */ +