gtsam/inference/tests/testJunctionTree.cpp

64 lines
2.0 KiB
C++

/**
* @file testJunctionTree.cpp
* @brief Unit tests for Junction Tree
* @author Kai Ni
* @author Frank Dellaert
*/
#include <boost/assign/std/list.hpp> // for operator +=
#include <boost/assign/std/set.hpp> // for operator +=
using namespace boost::assign;
#include <gtsam/CppUnitLite/TestHarness.h>
#define GTSAM_MAGIC_KEY
#include <gtsam/inference/Ordering.h>
#include <gtsam/inference/SymbolicFactorGraph.h>
#include <gtsam/inference/JunctionTree.h>
#include <gtsam/inference/ClusterTree-inl.h>
#include <gtsam/inference/JunctionTree-inl.h>
using namespace gtsam;
// explicit instantiation and typedef
template class JunctionTree<SymbolicFactorGraph>;
typedef JunctionTree<SymbolicFactorGraph> SymbolicJunctionTree;
/* ************************************************************************* *
* x1 - x2 - x3 - x4
* x3 x4
* x2 x1 : x3
****************************************************************************/
TEST( JunctionTree, constructor )
{
SymbolicFactorGraph fg;
fg.push_factor("x1","x2");
fg.push_factor("x2","x3");
fg.push_factor("x3","x4");
SymbolicJunctionTree expected;
Ordering ordering; ordering += "x2","x1","x3","x4";
SymbolicJunctionTree actual(fg, ordering);
// CHECK(assert_equal<SymbolicJunctionTree>(expected, actual));
Ordering frontal1; frontal1 += "x3", "x4";
Ordering frontal2; frontal2 += "x2", "x1";
Unordered sep1;
Unordered sep2; sep2 += "x3";
CHECK(assert_equal(frontal1, actual.root()->frontal_));
CHECK(assert_equal(sep1, actual.root()->separator_));
LONGS_EQUAL(1, actual.root()->size());
CHECK(assert_equal(frontal2, actual.root()->children_[0]->frontal_));
CHECK(assert_equal(sep2, actual.root()->children_[0]->separator_));
LONGS_EQUAL(2, actual.root()->children_[0]->size());
}
/* ************************************************************************* */
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */