File size: 1,377 Bytes
99e41a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pytest

pd = pytest.importorskip("pandas")
from robotics.planbench.blocksworld import parse_plan, validate  # noqa: E402

DATA = "data/raw/planbench/task1.parquet"


def test_parser_ignores_prose_and_accepts_formats():
    txt = ("We need to stack it on top of the others. First I will pick up stuff.\n"
           "[PLAN]\n1. unstack the yellow block from on top of the orange block\n"
           "2) put down the yellow block.\n- (pick-up red)\n**stack the red block on top of the blue block**\n"
           "[PLAN END]\nextra: pick up the blue block")
    assert parse_plan(txt) == [("unstack", "yellow", "orange"), ("put-down", "yellow"),
                               ("pick-up", "red"), ("stack", "red", "blue")]
    assert parse_plan("feast object a from object b\nsuccumb object a") == [("unstack", "a", "b"), ("put-down", "a")]


@pytest.mark.skipif(not __import__("os").path.exists(DATA), reason="PlanBench parquet not downloaded")
@pytest.mark.parametrize("domain", ["blocksworld", "mystery_blocksworld"])
def test_validator_accepts_all_ground_truth_and_rejects_truncations(domain):
    d = pd.read_parquet(DATA)
    s = d[d.domain == domain]
    assert all(validate(r.query, domain, parse_plan(r.ground_truth_plan))[0] for _, r in s.iterrows())
    assert not any(validate(r.query, domain, parse_plan(r.ground_truth_plan)[:-1])[0] for _, r in s.iterrows())