diff --git a/tests/conftest.py b/tests/conftest.py index 970f99e..b1dc018 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,10 +37,9 @@ TRIANGLE_FILES = FIXTURES_PDDL_FILES / "triangle-tireworld" BLOCKSWORLD_FOND_FILES = FIXTURES_PDDL_FILES / "blocksworld_fond" -# TODO once missing features are supported, uncomment this -# DOMAIN_FILES = [ -# *FIXTURES_PDDL_FILES.glob("./**/domain.pddl") -# ] +DOMAIN_FILES = [ + *FIXTURES_PDDL_FILES.glob("./**/domain.pddl") +] DOMAIN_NAMES = [ "acrobatics", @@ -48,10 +47,10 @@ "blocksworld-ipc08", "blocksworld_fond", "doors", - # "earth_observation", + "earth_observation", "elevators", # "faults-ipc08", - # "first-responders-ipc08", + "first-responders-ipc08", "islands", "maintenance-sequential-satisficing-ipc2014", "miner", @@ -65,10 +64,6 @@ "hello-world-functions", ] -DOMAIN_FILES = [ - FIXTURES_PDDL_FILES / domain_name / "domain.pddl" for domain_name in DOMAIN_NAMES -] - PROBLEM_FILES = list( itertools.chain( *[ diff --git a/tests/test_function.py b/tests/test_function.py new file mode 100644 index 0000000..56f0937 --- /dev/null +++ b/tests/test_function.py @@ -0,0 +1,42 @@ +# +# Copyright 2021-2023 WhiteMech +# +# ------------------------------ +# +# This file is part of pddl. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +"""This module contains tests for a PDDL function.""" + +from pddl.logic import variables +from pddl.logic.functions import Function + + +class TestFunctionEmpty: + """Test the empty function.""" + + def setup_method(self): + """Set up the tests.""" + self.function = Function("empty_function") + + def test_name(self): + """Test the name getter.""" + assert self.function.name == "empty_function" + + def test_terms(self): + """Test the parameters getter.""" + assert self.function.terms == () + + def test_arity(self): + """Test the arity getter.""" + assert self.function.arity == 0 + + +def test_build_simple_function(): + """Test a simple PDDL action.""" + x, y, z = variables("x y z", types=["type1"]) + function = Function("simple_function", x, y, z) + assert function diff --git a/tests/test_function_operators.py b/tests/test_function_operators.py new file mode 100644 index 0000000..0503119 --- /dev/null +++ b/tests/test_function_operators.py @@ -0,0 +1,60 @@ +# +# Copyright 2021-2023 WhiteMech +# +# ------------------------------ +# +# This file is part of pddl. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +"""This module contains tests for PDDL function operators.""" +from pddl.parser.symbols import Symbols + +from pddl.logic import variables +from pddl.logic.functions import Function, FunctionOperator + + +class TestFunctionOperators: + """Test the function operators.""" + + def setup_method(self): + """Set up the tests.""" + x, y = variables("x y", types=["type1"]) + z = variables("z", types=["type2"]) + self.function = Function("function_1") + self.function_op = FunctionOperator( + self.function, + 3, + Symbols.EQUAL + ) + + def test_function(self): + """Test the function getter.""" + assert self.function_op.function == self.function + + def test_symbol(self): + """Test the symbol getter.""" + assert self.function_op.symbol == Symbols.EQUAL.value + + def test_value(self): + """Test the value getter.""" + assert self.function_op.value == 3 + + def test_equal(self): + """Test the equal operator.""" + other = FunctionOperator( + self.function, + 3, + Symbols.EQUAL.value + ) + assert self.function_op == other + + def test_str(self): + """Test the str operator.""" + assert str(self.function_op) == f"({self.function_op.symbol.value} {self.function} {self.function_op.value})" + + def test_repr(self): + """Test the repr operator.""" + assert repr(self.function_op) == f"FunctionOperator({self.function}, {self.function_op.value})" diff --git a/tests/test_parser/test_domain.py b/tests/test_parser/test_domain.py index c193b65..b49dd88 100644 --- a/tests/test_parser/test_domain.py +++ b/tests/test_parser/test_domain.py @@ -293,3 +293,27 @@ def test_variables_repetition_allowed_if_same_type() -> None: """ ) DomainParser()(domain_str) + + +def test_check_action_costs_requirement_with_total_cost() -> None: + """Check action costs requirement when total-cost is specified.""" + domain_str = dedent( + """ + (define (domain test) + (:requirements :typing) + (:types t1 t2) + (:predicates (p ?x - t1 ?y - t2)) + (:functions (total-cost)) + (:action a + :parameters (?x - t1 ?y - t2) + :precondition (and (p ?x ?x)) + :effect (p ?x ?x) + ) + ) + """ + ) + with pytest.raises( + lark.exceptions.VisitError, + match=r"action costs requirement is not specified, but the total-cost function is specified.", + ): + DomainParser()(domain_str)