Spaces:
Sleeping
Sleeping
| """Unit tests for text-to-action parsing.""" | |
| from MiniGridEnv.env.action_parser import parse_action | |
| def test_exact_match(): | |
| assert parse_action("go forward") == (2, "go forward", True) | |
| def test_case_insensitive(): | |
| assert parse_action("Turn Left") == (0, "turn left", True) | |
| def test_structured_format(): | |
| action_idx, canonical, valid = parse_action("Thought: I see a key.\nAction: pickup") | |
| assert (action_idx, canonical, valid) == (3, "pickup", True) | |
| def test_alias(): | |
| assert parse_action("left") == (0, "turn left", True) | |
| def test_substring(): | |
| assert parse_action("I should go forward now") == (2, "go forward", True) | |
| def test_invalid_fallback(): | |
| action_idx, canonical, valid = parse_action("fly to the moon") | |
| assert (action_idx, canonical, valid) == (2, "go forward", False) | |
| def test_all_canonical_actions(): | |
| expected = [ | |
| ("turn left", 0), | |
| ("turn right", 1), | |
| ("go forward", 2), | |
| ("pickup", 3), | |
| ("drop", 4), | |
| ("toggle", 5), | |
| ("done", 6), | |
| ] | |
| for command, index in expected: | |
| assert parse_action(command)[0] == index | |
| def test_whitespace_handling(): | |
| assert parse_action(" go forward \n") == (2, "go forward", True) | |