add test demonstrating apply does not enumerate all leaves
parent
e3d68e772e
commit
e2bc0fac6b
|
@ -786,7 +786,6 @@ namespace gtsam {
|
||||||
template <typename L, typename Y>
|
template <typename L, typename Y>
|
||||||
DecisionTree<L, Y> DecisionTree<L, Y>::apply(
|
DecisionTree<L, Y> DecisionTree<L, Y>::apply(
|
||||||
const UnaryAssignment& op) const {
|
const UnaryAssignment& op) const {
|
||||||
std::cout << "Calling the correct apply" << std::endl;
|
|
||||||
// It is unclear what should happen if tree is empty:
|
// It is unclear what should happen if tree is empty:
|
||||||
if (empty()) {
|
if (empty()) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
|
|
|
@ -462,7 +462,7 @@ TEST(DecisionTree, ApplyWithAssignment) {
|
||||||
|
|
||||||
DecisionTree<string, double> probTree(
|
DecisionTree<string, double> probTree(
|
||||||
keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
|
keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08");
|
||||||
double threshold = 0.035;
|
double threshold = 0.045;
|
||||||
|
|
||||||
// We test pruning one tree by indexing into another.
|
// We test pruning one tree by indexing into another.
|
||||||
auto pruner = [&](const Assignment<string>& choices, const int& x) {
|
auto pruner = [&](const Assignment<string>& choices, const int& x) {
|
||||||
|
@ -475,8 +475,18 @@ TEST(DecisionTree, ApplyWithAssignment) {
|
||||||
};
|
};
|
||||||
DT prunedTree = tree.apply(pruner);
|
DT prunedTree = tree.apply(pruner);
|
||||||
|
|
||||||
DT expectedTree(keys, "0 0 0 4 5 6 7 8");
|
DT expectedTree(keys, "0 0 0 0 5 6 7 8");
|
||||||
EXPECT(assert_equal(expectedTree, prunedTree));
|
EXPECT(assert_equal(expectedTree, prunedTree));
|
||||||
|
|
||||||
|
size_t count = 0;
|
||||||
|
auto counter = [&](const Assignment<string>& choices, const int& x) {
|
||||||
|
count += 1;
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
DT prunedTree2 = prunedTree.apply(counter);
|
||||||
|
|
||||||
|
// Check if apply doesn't enumerate all leaves.
|
||||||
|
EXPECT_LONGS_EQUAL(5, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue