1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <catch.hpp>
#include <terraces/constraints.hpp>
#include <terraces/subtree_extraction.hpp>
#include <algorithm>
#include "../lib/trees_impl.hpp"
namespace terraces {
namespace tests {
TEST_CASE("constraint extraction: full data", "[subtree_extraction],[constraints]") {
tree t{{none, 4, 5, none}, {2, none, none, 0}, {4, 6, 1, none}, {4, none, none, 1},
{0, 2, 3, none}, {0, none, none, 2}, {2, none, none, 3}};
bitmatrix bm{4, 1};
for (index row = 0; row < bm.rows(); ++row) {
bm.set(row, 0, true);
}
auto ts = subtrees(t, bm);
auto result = compute_constraints(ts);
auto required = constraints{{1, 3, 2}, {0, 3, 1}};
CHECK(result == required);
}
TEST_CASE("constraint extraction: example", "[subtree_extraction],[constraints]") {
tree t{{none, 4, 5, none}, {2, none, none, 0}, {4, 6, 1, none}, {4, none, none, 1},
{0, 2, 3, none}, {0, none, none, 2}, {2, none, none, 3}};
bitmatrix bm{4, 2};
bm.set(0, 0, true);
bm.set(0, 1, true);
bm.set(1, 0, true);
bm.set(2, 0, true);
bm.set(2, 1, true);
bm.set(3, 1, true);
auto trees = subtrees(t, bm);
auto result = compute_constraints(trees);
auto required = constraints{{1, 0, 2}, {0, 3, 2}};
CHECK(result == required);
}
TEST_CASE("constraint deduplication", "[deduplication], [contraints]") {
auto dup = constraints{{0, 1, 2}, {0, 1, 2}, {3, 4, 5}, {4, 3, 5}, {7, 6, 8}, {6, 7, 8}};
auto num = deduplicate_constraints(dup);
CHECK(num == 3);
CHECK(dup == (constraints{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}));
}
} // namespace tests
} // namespace terraces
|