Commit 9bea44fc authored by Michal Sustr's avatar Michal Sustr
Browse files

Add incremental depth cache building test

parent 74a8aa98
......@@ -40,7 +40,7 @@ namespace algorithms {
void buildTree(EFGCache *cache, int maxDepth) {
auto traverse = [&cache, maxDepth](const shared_ptr<EFGNode> &node, const auto &traverse) {
if (node->getDepth() > maxDepth) return;
if (node->getDepth() >= maxDepth) return;
for (const auto &action : node->availableActions()) {
for (auto const &nodeDist : cache->getChildrenFor(node, action)) {
......
......@@ -40,7 +40,7 @@ using algorithms::buildTree;
BOOST_AUTO_TEST_SUITE(EFGTests)
BOOST_AUTO_TEST_CASE(BuildTree) {
BOOST_AUTO_TEST_CASE(BuildTreeMaxDepth) {
MatchingPenniesDomain mp;
auto rootNodes = createRootEFGNodes(mp.getRootStatesDistribution());
EFGCache cache(rootNodes);
......@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(BuildTree) {
BOOST_CHECK(!cache.hasChildren(rootNode, actions[1]));
rootNode->performAction(actions[0]);
rootNode->performAction(actions[0]);
rootNode->performAction(actions[1]);
BOOST_CHECK(!cache.hasChildren(rootNode));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[1]));
......@@ -67,6 +67,48 @@ BOOST_AUTO_TEST_CASE(BuildTree) {
// todo: make test(s) based on comparing domain statistics
}
BOOST_AUTO_TEST_CASE(BuildTreeLimitedDepth) {
MatchingPenniesDomain mp;
auto rootNodes = createRootEFGNodes(mp.getRootStatesDistribution());
EFGCache cache(rootNodes);
auto rootNode = rootNodes[0].first;
auto actions = rootNode->availableActions();
BOOST_CHECK(cache.hasNode(rootNode));
BOOST_CHECK(cache.hasInfoset(rootNode->getAOHInfSet()));
BOOST_CHECK(!cache.hasChildren(rootNode));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[1]));
auto node0 = rootNode->performAction(actions[0])[0].first;
auto node1 = rootNode->performAction(actions[1])[0].first;
BOOST_CHECK(!cache.hasChildren(rootNode));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[1]));
buildTree(&cache, 0);
BOOST_CHECK(!cache.hasChildren(rootNode));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(!cache.hasChildren(rootNode, actions[1]));
BOOST_CHECK(!cache.hasChildren(node0));
BOOST_CHECK(!cache.hasChildren(node1));
buildTree(&cache, 1);
BOOST_CHECK(cache.hasChildren(rootNode));
BOOST_CHECK(cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(cache.hasChildren(rootNode, actions[1]));
BOOST_CHECK(!cache.hasChildren(node0));
BOOST_CHECK(!cache.hasChildren(node1));
buildTree(&cache, 2);
BOOST_CHECK(cache.hasChildren(rootNode));
BOOST_CHECK(cache.hasChildren(rootNode, actions[0]));
BOOST_CHECK(cache.hasChildren(rootNode, actions[1]));
BOOST_CHECK(cache.hasChildren(node0));
BOOST_CHECK(cache.hasChildren(node1));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace GTLib2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment