OLD | NEW |
(Empty) | |
| 1 try: |
| 2 # Python 2 |
| 3 from StringIO import StringIO |
| 4 except ImportError: |
| 5 # Python 3 |
| 6 from io import StringIO |
| 7 |
| 8 import pddl |
| 9 from pddl_to_prolog import Rule, PrologProgram |
| 10 |
| 11 def test_normalization(): |
| 12 prog = PrologProgram() |
| 13 prog.add_fact(pddl.Atom("at", ["foo", "bar"])) |
| 14 prog.add_fact(pddl.Atom("truck", ["bollerwagen"])) |
| 15 prog.add_fact(pddl.Atom("truck", ["segway"])) |
| 16 prog.add_rule(Rule([pddl.Atom("truck", ["?X"])], pddl.Atom("at", ["?X", "?Y"
]))) |
| 17 prog.add_rule(Rule([pddl.Atom("truck", ["X"]), pddl.Atom("location", ["?Y"])
], |
| 18 pddl.Atom("at", ["?X", "?Y"]))) |
| 19 prog.add_rule(Rule([pddl.Atom("truck", ["?X"]), pddl.Atom("location", ["?Y"]
)], |
| 20 pddl.Atom("at", ["?X", "?X"]))) |
| 21 prog.add_rule(Rule([pddl.Atom("p", ["?Y", "?Z", "?Y", "?Z"])], |
| 22 pddl.Atom("q", ["?Y", "?Y"]))) |
| 23 prog.add_rule(Rule([], pddl.Atom("foo", []))) |
| 24 prog.add_rule(Rule([], pddl.Atom("bar", ["X"]))) |
| 25 prog.normalize() |
| 26 output = StringIO() |
| 27 prog.dump(file=output) |
| 28 assert output.getvalue() == """\ |
| 29 Atom at(foo, bar). |
| 30 Atom truck(bollerwagen). |
| 31 Atom truck(segway). |
| 32 Atom @object(bollerwagen). |
| 33 Atom @object(foo). |
| 34 Atom @object(bar). |
| 35 Atom @object(segway). |
| 36 Atom foo(). |
| 37 Atom bar(X). |
| 38 none Atom at(?X, ?Y) :- Atom truck(?X), Atom @object(?Y). |
| 39 none Atom at(?X, ?Y) :- Atom truck(X), Atom location(?Y), Atom @object(?X). |
| 40 none Atom at(?X, ?X@0) :- Atom truck(?X), Atom location(?Y), Atom =(?X, ?X@0). |
| 41 none Atom q(?Y, ?Y@0) :- Atom p(?Y, ?Z, ?Y, ?Z), Atom =(?Y, ?Y@0), Atom =(?Y, ?Y
@1), Atom =(?Z, ?Z@2). |
| 42 """ |
OLD | NEW |