Skip to content

Commit

Permalink
Merge pull request #69 from AI-Planning/fix/tostring
Browse files Browse the repository at this point in the history
Fix/tostring
  • Loading branch information
haz committed May 25, 2023
2 parents 2c9655a + 3cf98dc commit ddcb467
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pddl/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _print_predicates_with_types(predicates: Collection):
result += (
f" ?{t.name} - {' '.join(t.type_tags)}"
if t.type_tags
else f"?{t.name}"
else f" ?{t.name}"
)
result += ") "
result += " "
Expand Down
4 changes: 2 additions & 2 deletions pddl/logic/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def __hash__(self) -> int:

def __str__(self) -> str:
"""Get the string representation."""
return f"({Symbols.EQUAL} {self.left} {self.right})"
return f"({Symbols.EQUAL.value} {self.left} {self.right})"

def __repr__(self) -> str:
"""Get the string representation."""
return f"{type(self).__name__}({self.left}, {self.right})"
return f"{type(self).__name__}({repr(self.left)}, {repr(self.right)})"


@cache_hash
Expand Down
33 changes: 32 additions & 1 deletion tests/test_predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"""This module contains tests for PDDL predicates."""
from pddl.core import Predicate
from pddl.logic.helpers import variables
from pddl.logic.predicates import EqualTo


class TestPredicateSimpleInitialisation:
"""Test simple predicate initialisation."""

def setup(self):
def setup_method(self):
"""Set up the tests."""
self.a, self.b = variables("a b")
self.predicate = Predicate("P", self.a, self.b)
Expand All @@ -34,3 +35,33 @@ def test_variables(self):
def test_arity(self):
"""Test arity property."""
assert self.predicate.arity == 2


class TestEqualToPredicate:
"""Test the eaual to predicate."""

def setup_method(self):
"""Set up the tests."""
self.left, self.right = variables("l r")
self.equal_to = EqualTo(self.left, self.right)

def test_left(self):
"""Test left getter."""
assert self.equal_to.left == self.left

def test_right(self):
"""Test right getter."""
assert self.equal_to.right == self.right

def test_to_equal(self):
"""Test to equal."""
other = EqualTo(self.left, self.right)
assert self.equal_to == other

def test_to_str(self):
"""Test to string."""
assert str(self.equal_to) == f"(= {str(self.left)} {str(self.right)})"

def test_to_repr(self):
"""Test to repr."""
assert repr(self.equal_to) == f"EqualTo({repr(self.left)}, {repr(self.right)})"

0 comments on commit ddcb467

Please sign in to comment.