diff --git a/gtsam/discrete/tests/testTableFactor.cpp b/gtsam/discrete/tests/testTableFactor.cpp index 212067cb3..7df6da83e 100644 --- a/gtsam/discrete/tests/testTableFactor.cpp +++ b/gtsam/discrete/tests/testTableFactor.cpp @@ -147,6 +147,36 @@ TEST(TableFactor, constructors) { EXPECT(assert_inequal(f5_with_wrong_keys, f5, 1e-9)); } +/* ************************************************************************* */ +// Check conversion from DecisionTreeFactor. +TEST(TableFactor, Conversion) { + /* This is the DecisionTree we are using + Choice(m2) + 0 Choice(m1) + 0 0 Leaf 0 + 0 1 Choice(m0) + 0 1 0 Leaf 0 + 0 1 1 Leaf 0.14649446 // 3 + 1 Choice(m1) + 1 0 Choice(m0) + 1 0 0 Leaf 0 + 1 0 1 Leaf 0.14648756 // 5 + 1 1 Choice(m0) + 1 1 0 Leaf 0.14649446 // 6 + 1 1 1 Leaf 0.23918345 // 7 + */ + DiscreteKeys dkeys = {{0, 2}, {1, 2}, {2, 2}}; + DecisionTreeFactor dtf( + dkeys, std::vector{0, 0, 0, 0.14649446, 0, 0.14648756, 0.14649446, + 0.23918345}); + + // dtf.print(); + TableFactor tf(dtf.discreteKeys(), dtf); + // tf.print(); + // tf.toDecisionTreeFactor().print(); + EXPECT(assert_equal(dtf, tf.toDecisionTreeFactor())); +} + /* ************************************************************************* */ // Check multiplication between two TableFactors. TEST(TableFactor, multiplication) {