Skip to content

Commit

Permalink
add some further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francescofuggitti committed Oct 9, 2023
1 parent 53a106e commit 92b0113
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@
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",
"beam-walk",
"blocksworld-ipc08",
"blocksworld_fond",
"doors",
# "earth_observation",
"earth_observation",
"elevators",
# "faults-ipc08",
# "first-responders-ipc08",
"first-responders-ipc08",
"islands",
"maintenance-sequential-satisficing-ipc2014",
"miner",
Expand All @@ -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(
*[
Expand Down
42 changes: 42 additions & 0 deletions tests/test_function.py
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions tests/test_function_operators.py
Original file line number Diff line number Diff line change
@@ -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})"
24 changes: 24 additions & 0 deletions tests/test_parser/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 92b0113

Please sign in to comment.