def _update_backward(self, command: Command, state: State) -> State: assert command.opcode == "backward" backward_meters, = command.operands move_direction = state.orientation_degrees + 180 state = state.copy_and_set_time_used_seconds( state.time_used_seconds + backward_meters / self.drone_config.speed_mps) state = state.copy_and_set_x_meters(state.x_meters + backward_meters * sin(radians(move_direction))) state = state.copy_and_set_y_meters(state.y_meters + backward_meters * cos(radians(move_direction))) return state
def test_copy_and_set_y_meters(self): state = State() actual = state.copy_and_set_y_meters(1) expected = State(has_taken_off=False, time_used_seconds=0, x_meters=0, y_meters=1, z_meters=0, orientation_degrees=0) self.assertEqual(expected, actual)