def check_statement_condition_accepts_value(self, statement_type: type): condition = Condition(False) statement = statement_type(action="", effect=Condition(False), condition=condition, duration=2) self.assertEqual(statement.condition, condition)
def test_conditional_releases(self): statement = parsing.statement.parse( "Use releases broken if unlucky by lol") broken, unlucky = sympy.symbols("broken,unlucky") self.assertEqual( Releases(action="Use", effect=Condition(broken), condition=Condition(unlucky), agent="lol"), statement)
def test_conditional_causes(self): statement = parsing.statement.parse( "Charge causes charged if plugged_in by Teddy") charged, plugged_in = sympy.symbols("charged,plugged_in") self.assertEqual( Causes(action="Charge", effect=Condition(charged), condition=Condition(plugged_in), agent="Teddy"), statement)
def test_conditional_releases(self): statement = parsing.statement.parse( "Use releases broken if unlucky during 14") broken, unlucky = sympy.symbols("broken,unlucky") self.assertEqual( statement, Releases(action="Use", effect=Condition(broken), condition=Condition(unlucky), duration=14))
def test_conditional_causes(self): statement = parsing.statement.parse( "Charge causes charged if plugged_in during 6") charged, plugged_in = sympy.symbols("charged,plugged_in") self.assertEqual( statement, Causes(action="Charge", effect=Condition(charged), condition=Condition(plugged_in), duration=6))
def join_statement_by_and(self, statement1: Statement, statement2: Statement, is_causes: bool) -> Statement: if is_causes: return Causes(action=statement1.action, effect=Condition( And(statement1.effect.formula, statement2.effect.formula)), duration=statement1.duration) else: return Releases(action=statement1.action, effect=Condition( And(statement1.effect.formula, statement2.effect.formula)), duration=statement1.duration)
def create_tautology_from_statements(self, statement1: Statement, statement2: Statement) -> Statement: return Releases(action=statement1.action, effect=Condition( Or(statement1.effect.formula, Not(statement2.effect.formula))), duration=statement1.duration, agent=statement1.agent)
def test_test(self): scenario = parsing.scenario.parse_file("example/scenario.txt") self.assertEqual(len(scenario.observations), 2) alive, loaded, hidden = sympy.symbols("alive,loaded,hidden") self.assertEqual(scenario.observations[0], Observation( begin_time=0, condition=Condition(alive & ~loaded & hidden))) self.assertEqual(scenario.observations[1], Observation( begin_time=2, condition=Condition(alive & ~loaded & ~hidden))) self.assertEqual(len(scenario.action_occurrences), 2) self.assertEqual(scenario.action_occurrences[0], ActionOccurrence(name="Load", begin_time=1, duration=2)) self.assertEqual(scenario.action_occurrences[1], ActionOccurrence(name="Shoot", begin_time=3, duration=1))
def test_parse_example(self): description = parsing.domain_description.parse_file("example/lib.adl3") self.assertEqual(len(description.statements), 5) alive, loaded, hidden = sympy.symbols("alive,loaded,hidden") self.assertTrue(isinstance(description.statements[0], Releases)) self.assertEqual( description.statements[0], Releases(action="Load", effect=Condition(loaded), duration=2)) self.assertTrue(isinstance(description.statements[1], Releases)) self.assertEqual( description.statements[1], Releases(action="Load", effect=Condition(~hidden), duration=1)) self.assertTrue(isinstance(description.statements[2], Causes)) self.assertEqual( description.statements[2], Causes(action="Shoot", effect=Condition(~loaded), duration=1)) self.assertTrue(isinstance(description.statements[3], Causes)) self.assertEqual( description.statements[3], Causes(action="Shoot", effect=Condition(~alive), condition=Condition(~hidden & loaded), duration=1)) self.assertTrue(isinstance(description.statements[4], ImpossibleIf)) self.assertEqual( description.statements[4], ImpossibleIf(action="Shoot", condition=Condition(~loaded)))
def test_parse_example(self): os.chdir(os.path.dirname(os.path.abspath(__file__))) description = parsing.domain_description.parse_file( "../example/lib.adl3") self.assertEqual(len(description.statements), 5) alive, loaded, hidden = sympy.symbols("alive,loaded,hidden") ##### self.assertTrue(isinstance(description.statements[0], Causes)) self.assertEqual( Causes(action="load", effect=Condition(loaded), agent="hunter"), description.statements[0]) ##### self.assertTrue(isinstance(description.statements[1], Causes)) self.assertEqual( Causes(action="shoot", effect=Condition(~loaded), agent="hunter"), description.statements[1]) ##### self.assertTrue(isinstance(description.statements[2], Causes)) self.assertEqual( Causes(action="shoot", effect=Condition(~alive), condition=Condition(loaded & ~hidden), agent="hunter"), description.statements[2]) ##### self.assertTrue(isinstance(description.statements[3], Releases)) self.assertEqual( Releases(action="escape", effect=Condition(hidden), agent="turkey"), description.statements[3]) ##### self.assertTrue(isinstance(description.statements[4], Triggers)) self.assertEqual( Triggers(action="escape", condition=Condition(loaded)), description.statements[4])
def test_unconditional_releases(self): statement = parsing.statement.parse("Use releases broken during 14") broken = sympy.symbols("broken") self.assertEqual( statement, Releases(action="Use", effect=Condition(broken), duration=14))
def parse(input: str) -> Condition: return Condition(sympy_parser.parse_expr(input))
def parse(input: str) -> Union[Condition, bool]: if input is None: return True return Condition(sympy_parser.parse_expr(input))
def test_triggers(self): statement = parsing.statement.parse("detonate triggers explosion") detonate = sympy.symbols("detonate") self.assertEqual( Triggers(action="explosion", condition=Condition(detonate)), statement)
def test_unconditional_releases(self): statement = parsing.statement.parse("Use releases broken by lol") broken = sympy.symbols("broken") self.assertEqual( Releases(action="Use", effect=Condition(broken), agent="lol"), statement)
def test_unconditional_causes(self): statement = parsing.statement.parse("Charge causes charged during 6") charged = sympy.symbols("charged") self.assertEqual( statement, Causes(action="Charge", effect=Condition(charged), duration=6))
def test_unconditional_causes(self): statement = parsing.statement.parse("Charge causes charged by Kuba") charged = sympy.symbols("charged") self.assertEqual( Causes(action="Charge", effect=Condition(charged), agent="Kuba"), statement)
def check_statement_condition_defaults_to_true(self, statement_type: type): statement = statement_type(action="", effect=Condition(False), duration=2) self.assertEqual(statement.condition, True)