Add more pruning tests

This commit is contained in:
Robert Haschke 2021-11-19 00:17:28 +01:00
parent 66e141db7b
commit 011e4be059
2 changed files with 54 additions and 8 deletions

View File

@ -5,6 +5,10 @@
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#ifndef TYPED_TEST_SUITE
#define TYPED_TEST_SUITE(SUITE, TYPES) TYPED_TEST_CASE(SUITE, TYPES)
#endif
namespace mtc = moveit::task_constructor;
// type-trait functions for OrderedTest<T>
@ -62,11 +66,7 @@ protected:
};
// set of template types to test for
using TypeInstances = ::testing::Types<int, int*, mtc::SolutionBasePtr, mtc::SolutionBaseConstPtr>;
#ifdef TYPED_TEST_SUITE
TYPED_TEST_SUITE(ValueOrPointeeLessTest, TypeInstances);
#else
TYPED_TEST_CASE(ValueOrPointeeLessTest, TypeInstances);
#endif
TYPED_TEST(ValueOrPointeeLessTest, less) {
EXPECT_TRUE(this->less(2, 3));
EXPECT_FALSE(this->less(1, 1));
@ -105,11 +105,7 @@ protected:
SCOPED_TRACE("pushAndValidate(" #cost ", " #__VA_ARGS__ ")"); \
this->pushAndValidate(cost, __VA_ARGS__); \
}
#ifdef TYPED_TEST_SUITE
TYPED_TEST_SUITE(OrderedTest, TypeInstances);
#else
TYPED_TEST_CASE(OrderedTest, TypeInstances);
#endif
TYPED_TEST(OrderedTest, sorting) {
pushAndValidate(2, { 2 });
pushAndValidate(1, { 1, 2 });

View File

@ -8,6 +8,10 @@
#include <gtest/gtest.h>
#ifndef TYPED_TEST_SUITE
#define TYPED_TEST_SUITE(SUITE, TYPES) TYPED_TEST_CASE(SUITE, TYPES)
#endif
using namespace moveit::task_constructor;
using Pruning = TaskTestBase;
@ -40,6 +44,52 @@ TEST_F(Pruning, PruningMultiForward) {
EXPECT_EQ((*t.solutions().begin())->cost(), 0u);
}
// The 2nd failing FW attempt would prune the path through CON,
// but shouldn't because there exist two more GEN2 solutions
TEST_F(Pruning, NoPruningIfAlternativesExist) {
add(t, new GeneratorMockup(PredefinedCosts({ 0.0 })));
add(t, new ConnectMockup());
add(t, new GeneratorMockup(std::list<double>{ 0, 10, 20, 30 }, 2));
add(t, new ForwardMockup({ INF, INF, 0.0, INF }));
t.plan();
EXPECT_EQ(t.solutions().size(), 1u);
}
TEST_F(Pruning, ConnectReactivatesPrunedPaths) {
add(t, new BackwardMockup);
add(t, new GeneratorMockup({ 0 }));
add(t, new ConnectMockup());
// the solution here should re-activate the initially pruned backward path
add(t, new GeneratorMockup({ 0 }));
EXPECT_TRUE(t.plan());
EXPECT_EQ(t.solutions().size(), 1u);
}
// same as before, but wrapping Connect into a container
template <typename T>
struct PruningContainerTests : public Pruning
{
void test() {
add(t, new BackwardMockup);
add(t, new GeneratorMockup({ 0 }));
auto c = new T();
add(*c, new ConnectMockup());
add(t, c);
add(t, new GeneratorMockup({ 0 }));
EXPECT_TRUE(t.plan());
EXPECT_EQ(t.solutions().size(), 1u);
}
};
using ContainerTypes = ::testing::Types<SerialContainer, Fallbacks>;
TYPED_TEST_SUITE(PruningContainerTests, ContainerTypes);
TYPED_TEST(PruningContainerTests, ConnectReactivatesPrunedPaths) {
this->test();
}
TEST_F(Pruning, ConnectConnectForward) {
add(t, new GeneratorMockup());
auto c1 = add(t, new ConnectMockup({ INF, 0, 0 })); // 1st attempt is a failue