Ejemplo n.º 1
0
 def test_impossible_action(self):
     class Impossible(Action):
         def apply(self, state_dict):
             raise ImpossibleActionException()
     with self.assertRaises(ImpossiblePlanSearchException):
         # The plan should not raise an ImpossibleActionException
         plan_search(['bob'], self.state, [Impossible], self.goal_fn, convince=False)
Ejemplo n.º 2
0
    def test_impossible(self):
        """ Test finding a plan to an impossible goal. """
        def too_few_toes(state):
            state_dict = state.as_dict()
            return state_dict['characters']['alice']['toes'] <= 7

        with self.assertRaises(ImpossiblePlanSearchException):
            plan_search(['alice'], self.state, [self.action], too_few_toes)
Ejemplo n.º 3
0
 def test_plan_bob_kill_bob(self):
     plan = plan_search(['bob'], self.state, [Kill], self.goal_fn)
     self.assertEqual(
         str(plan),
         str(Plan(actions=[
             Kill(['bob'], ['bob'])
         ]))
     )
Ejemplo n.º 4
0
 def test_multi_step(self):
     plan = plan_search(['alice'], self.state, [self.action], self.goal_fn)
     self.assertEqual(
         str(plan),
         str(Plan(actions=[
             self.action(['alice'], ['alice']),
             self.action(['alice'], ['alice'])
         ]))
     )
Ejemplo n.º 5
0
 def test_convince_plan(self):
     """ Test finding a plan where somebody must be convinced to perform an action. """
     plan = plan_search(['alice'], self.state, [self.give_money], self.goal_fn)
     self.assertEqual(
         str(plan),
         str(Plan(actions=[
             Convince(['alice'], ['bob']),
             self.give_money(['bob'], ['carol']),
             EndConvince(['alice'], ['bob'])
         ]))
     )
Ejemplo n.º 6
0
 def test_already_satisfied(self):
     self.initial_state_dict['characters']['bob']['alive'] = False
     state = State.from_dict(self.initial_state_dict)
     plan = plan_search(['alice'], state, [Kill], self.goal_fn)
     self.assertIsNone(plan)