def test_travel_distance(self): action = Action() action.action_point = lambda org: self.action_point self.assertEqual( action.travel_distance(self.robot_position), # from robot to first to second math.sqrt(30 * 30 + 10 * 10) + math.sqrt(60 * 60 + 50 * 50))
def test_set_state(self): action = Action() for state in [ ActionStatus.IDLE, ActionStatus.PAUSED, ActionStatus.DONE, ActionStatus.RUNNING ]: action.state = state self.assertEqual(state, action.state, "state is set to {}".format(state))
def test_action_point(self): """ Test action point computation for dock_control performer. """ # Create move action action = Action.parse_string("<dock_control />") #action.arguments.set("argname", value) # Test computation self.assertEqual(self.action_point, action.action_point(self.robot_position), "compute action point with remote service")
def test_perform_success(self): self.action_state = ActionStatus.IDLE self.pc.perform_action(Action.parse_string("<template />"), Pose2D()) # Wait for result start = time() while not rospy.is_shutdown() and time() - start < 1 \ and self.action_state == ActionStatus.IDLE: sleep(0.1) # Assert action performed self.assertEqual(self.action_state, ActionStatus.DONE, "right action status")
def test_priority(self): action = Action() action.points = 30 action.travel_distance = lambda org: 78 self.assertEqual(action.priority(self.robot_position), 900 / 78, "compute regular priority") # Distance to 0 action.travel_distance = lambda org: 0 self.assertEqual(action.priority(self.robot_position), math.inf, "compute priority with travel distance to 0")
def test_action_parsing(self): parsed = Action.parse_string(""" <parse native="true" points="34"> <arg name="file">yes</arg> <arg name="smthg">34</arg> </parse> """) self.assertEqual(parsed.name, "parse", "name parsed") self.assertEqual(parsed.native, True, "native parsed") self.assertEqual(parsed.repeat, None, "native parsed") self.assertEqual(parsed.points, 34) self.assertEqual(parsed.arguments.get("file"), "yes") self.assertEqual(parsed.arguments.get("smthg", int), 34)
def test_action_point(self): # Create move action action = Action.parse_string(""" <move native='true'> <arg name="x">90</arg> <arg name="y">60</arg> <arg name="theta">0</arg> </move> """) # Test computation self.assertEqual(self.action_point, action.action_point(self.first_position), "compute with remote service") # Change settings to test cache (not supposed to be re-set) action.arguments.set("x", 25) action.arguments.set("y", 10) action.arguments.set("theta", 40) # Test usage of cache (almost same condition) self.assertEqual(self.action_point, action.action_point(self.first_position), "does not recompute with cache")