-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements in the parsing of typed lists #82
Changes from 1 commit
e3a249e
658dc62
d7d0534
d5b509c
3c53e3f
3cf8cb4
cf25df5
ccb5097
7a7836c
f1e3316
48ffa56
976f481
889b3fc
73e4fac
d2dded9
67d3b1d
124a60a
03abf7d
04fe2f8
1a35939
c3ab1aa
35f333b
529d35d
0d264a8
03e632b
f232127
1586db1
e879efb
771c6fc
2d35e8c
190a7c5
4376e54
a511022
3d02538
617cfd7
bdddfbf
7b3e7ad
a12e34b
f0e79af
8c41830
eb2429d
9a16858
a6367ba
2c67fde
b8e0a2b
3661f64
924c88c
f7996d1
f5858b3
edcc295
97b379f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,14 @@ | |
|
||
"""This module contains tests verifying that the formatter outputs are syntactically valid and semantically faithful.""" | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
from pddl.core import Domain, Problem | ||
from pddl.formatter import domain_to_string, problem_to_string | ||
from pddl.logic import constants | ||
from pddl.requirements import Requirements | ||
from tests.conftest import DOMAIN_FILES, PROBLEM_FILES | ||
|
||
|
||
|
@@ -36,3 +40,62 @@ def test_problem_formatter(problem_parser, pddl_file): | |
actual_problem_str = problem_to_string(expected_problem_obj) | ||
actual_problem_obj = problem_parser(actual_problem_str) | ||
assert actual_problem_obj == expected_problem_obj | ||
|
||
|
||
def test_typed_constants_formatting_in_domain() -> None: | ||
"""Test that types and typed constants are formatted correctly.""" | ||
t1, t2, t3 = "type_1", "type_2", "type_3" | ||
|
||
a1, b1, c1 = constants("a b c", type_=t1) | ||
d2, e2, f2 = constants("d e f", type_=t2) | ||
g3, h3, i3 = constants("g h i", type_=t3) | ||
j, k, lc = constants("j k l", type_=None) | ||
|
||
# define the domain object. | ||
domain = Domain( | ||
"my_domain", | ||
requirements=[Requirements.TYPING], | ||
types={t1: None, t2: t1, t3: t1}, | ||
constants=[a1, b1, c1, d2, e2, f2, g3, h3, i3, j, k, lc], | ||
) | ||
|
||
domain_str = domain_to_string(domain) | ||
|
||
assert domain_str == dedent( | ||
"""\ | ||
(define (domain my_domain) | ||
(:requirements :typing) | ||
(:types type_2 type_3 - type_1 type_1) | ||
(:constants a b c - type_1 d e f - type_2 g h i - type_3 j k l) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same applies here: first group by type, print groups by type name in alphanumerical order, and then print constants sorted within the group; however, constants with no type must be at the end. |
||
(:predicates ) | ||
)""" | ||
) | ||
|
||
|
||
def test_typed_objects_formatting_in_problem() -> None: | ||
"""Test that typed objects are formatted correctly.""" | ||
t1, t2, t3 = "type_1", "type_2", "type_3" | ||
|
||
a1, b1, c1 = constants("a b c", type_=t1) | ||
d2, e2, f2 = constants("d e f", type_=t2) | ||
g3, h3, i3 = constants("g h i", type_=t3) | ||
j, k, lc = constants("j k l", type_=None) | ||
|
||
problem = Problem( | ||
"problem-1", | ||
domain_name="my_domain", | ||
requirements=[Requirements.TYPING], | ||
objects=[a1, b1, c1, d2, e2, f2, g3, h3, i3, j, k, lc], | ||
) | ||
problem_str = problem_to_string(problem) | ||
|
||
assert problem_str == dedent( | ||
"""\ | ||
(define (problem problem-1) | ||
(:domain my_domain) | ||
(:requirements :typing) | ||
(:objects a b c - type_1 d e f - type_2 g h i - type_3 j k l) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same approach used for constants applies here. |
||
(:init ) | ||
(:goal (and)) | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should decide what to do with empty init and goal sections. The PDDL grammar specifies these sections are mandatory. We will tackle this in a next PR, taking into account formatter refactoring #72 |
||
)""" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, earlier we did not consider types with no parents, and we printed
![image](https://private-user-images.githubusercontent.com/9467617/245413964-30ec8961-5f75-475a-9d8d-ea0a8f3d1aaa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3MzYxMjMsIm5iZiI6MTcyMTczNTgyMywicGF0aCI6Ii85NDY3NjE3LzI0NTQxMzk2NC0zMGVjODk2MS01Zjc1LTQ3NWEtOWQ4ZC1lYTBhOGYzZDFhYWEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjNUMTE1NzAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjhjNjQ5YjZlYTc3NTU0MWQ4MTFmZTVjY2E5ODM3Njc4ZDc1MTM0MzUzM2I3ZGY4ZjVkNjVkODE2YThiZDU4NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LYw4FZVGCT-oUSPctk4viH0EY6_E6bATZZSSyqEyn5w)
type_1
in the first position. However, this is not correct wrt PDDL syntax; typed names with no type should be at the end of the list, o/w there is no way the parsing rules can spot them: