From 5a561488918a357e493f1e88ffdd6285febd70b8 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 2 Sep 2024 12:19:43 -0300 Subject: [PATCH] add test problem_expert.exist_precidate --- .../test/unit/problem_expert_test.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/plansys2_problem_expert/test/unit/problem_expert_test.cpp b/plansys2_problem_expert/test/unit/problem_expert_test.cpp index 906a8fe3..0ffeea32 100644 --- a/plansys2_problem_expert/test/unit/problem_expert_test.cpp +++ b/plansys2_problem_expert/test/unit/problem_expert_test.cpp @@ -747,6 +747,72 @@ TEST(problem_expert, is_goal_satisfied) ASSERT_TRUE(problem_expert.isGoalSatisfied(goal)); } +TEST(problem_expert, exist_predicate) +{ + std::string pkgpath = ament_index_cpp::get_package_share_directory("plansys2_problem_expert"); + std::ifstream domain_ifs(pkgpath + "/pddl/domain_simple_derived.pddl"); + std::string domain_str(( + std::istreambuf_iterator(domain_ifs)), + std::istreambuf_iterator()); + + auto domain_expert = std::make_shared(domain_str); + plansys2::ProblemExpert problem_expert(domain_expert); + + std::ifstream problem_ifs(pkgpath + "/pddl/problem_simple_1.pddl"); + std::string problem_str(( + std::istreambuf_iterator(problem_ifs)), + std::istreambuf_iterator()); + ASSERT_TRUE(problem_expert.addProblem(problem_str)); + + ASSERT_TRUE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(robot_at leia kitchen)"))); + ASSERT_TRUE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-robot_at leia kitchen)"))); + ASSERT_TRUE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(person_at jack bedroom)"))); + ASSERT_TRUE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-person_at jack bedroom)"))); + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-person_at jack kitchen)"))); + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-robot_at leia bedroom)"))); + + problem_expert.removePredicate( + parser::pddl::fromStringPredicate("(robot_at leia kitchen)")); + problem_expert.removePredicate( + parser::pddl::fromStringPredicate("(person_at jack bedroom)")); + + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-person_at jack bedroom)"))); + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(inferred-robot_at leia kitchen)"))); + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(person_at jack bedroom)"))); + ASSERT_FALSE( + problem_expert.existPredicate( + parser::pddl::fromStringPredicate( + "(robot_at leia kitchen)"))); + +} + int main(int argc, char ** argv) { testing::InitGoogleTest(&argc, argv);