Помогите, не могу исправить ошибку
Выдает ошибку:
in test_triple_free_space_algorithm
max_distance, left_corner, right_corner, wall_name = self.calculator.free_space_algorithm(objects, walls, walls_length)
TypeError: free_space_algorithm() takes 3 positional arguments but 4 were given
Сама Функция:
def free_space_algorithm(objects, walls, walls_length):
# Функция для определения наибольшего свободного пространства на планировке
# Функция для определения длины стены по координатам углов
def wall_length(wall_corners):
if wall_corners[0][0] == wall_corners[1][0]:
# Стена вертикальная
return abs(wall_corners[0][1] - wall_corners[1][1])
else:
# Стена горизонтальная
return abs(wall_corners[0][0] - wall_corners[1][0])
# Функция для определения координат прилегающих углов к стене
def adjacent_corners(object_corners, wall_corners):
adjacent = []
for corner in object_corners:
if wall_corners[0][0] == wall_corners[1][0]:
# Стена вертикальная
if corner[0] == wall_corners[0][0]:
adjacent.append(corner)
else:
# Стена горизонтальная
if corner[1] == wall_corners[0][1]:
adjacent.append(corner)
return adjacent
# Функция для определения длины прямой между двумя точками
def distance_between_points(point1, point2):
return math.hypot(point2[0] - point1[0], point2[1] - point1[1])
# Создаем словарь для записи длин и координат углов стен
wall_lengths = {}
for wall_name, wall_corners in walls.items():
wall_lengths[wall_name] = {"length": wall_length(wall_corners), "corners": wall_corners}
# Создаем словарь для записи расстояний между точками и координат углов
distances = {}
for i, object_corners in enumerate(objects):
for wall_name, wall_length in walls_length.items():
# Определяем прилегающие к стене углы объекта
wall_corners = walls[wall_name]
adjacent = adjacent_corners(object_corners, wall_corners)
if len(adjacent) == 2:
# Если есть два прилегающих угла, то считаем расстояние по стене
distance = distance_between_points(adjacent[0], adjacent[1])
distances[distance] = {"left_corner": adjacent[0], "right_corner": adjacent[1], "wall": wall_name}
elif len(adjacent) == 1:
# Если только один прилегающий угол, то считаем расстояние до противоположной стороны стены
# и записываем его как сумму двух отрезков
opposite_corner = [corner for corner in object_corners if corner not in adjacent][0]
opposite_wall_corner = [corner for corner in wall_corners if corner not in adjacent][0]
first_distance = distance_between_points(adjacent[0], opposite_corner)
second_distance = distance_between_points(opposite_corner, opposite_wall_corner)
distance = first_distance + second_distance
distances[distance] = {"left_corner": adjacent[0], "right_corner": opposite_wall_corner, "wall": wall_name}
# Удаляем повторяющиеся значения
unique_distances = {}
for k, v in distances.items():
if v["left_corner"] not in [i["left_corner"] for i in unique_distances.values()] and \
v["right_corner"] not in [i["right_corner"] for i in unique_distances.values()]:
unique_distances[k] = v
# Находим максимальное расстояние и возвращаем его соответствующие углы и стену
max_distance = max(unique_distances.keys())
max_distance_info = unique_distances[max_distance]
return max_distance, max_distance_info["left_corner"], max_distance_info["right_corner"], max_distance_info["wall"]
Функция в юниттесте:
class TestFurnitureArrangement(unittest.TestCase):
def setUp(self):
self.calculator = FurnitureArrangement()
def test_double_free_space_algorithm(self):
objects = [
[(1, 1), (2, 1), (2, 2), (1, 2)],
[(3, 1), (4, 1), (4, 2), (3, 2)],
[(1, 3), (2, 3), (2, 4), (1, 4)],
[(3, 3), (4, 3), (4, 4), (3, 4)]
]
walls = {
"wall1": [(0, 0), (0, 5)],
"wall2": [(0, 5), (5, 5)]
}
walls_length = {
"wall1": 5,
"wall2": 5
}
max_distance, left_corner, right_corner, wall = self.calculator.free_space_algorithm(objects, walls, walls_length)
self.assertAlmostEqual(max_distance, 4.24264069)
self.assertAlmostEqual(left_corner, (2, 2))
self.assertAlmostEqual(right_corner, (3, 3))
self.assertEqual(wall, "wall2")
def test_triple_free_space_algorithm(self):
objects = [
[(1, 1), (2, 1), (2, 2), (1, 2)],
[(3, 1), (4, 1), (4, 2), (3, 2)],
[(1, 3), (2, 3), (2, 4), (1, 4)],
[(3, 3), (4, 3), (4, 4), (3, 4)]
]
walls = {
"wall1": [(0, 0), (0, 5)],
"wall2": [(0, 5), (5, 5)],
"wall3": [(5, 5), (5, 0)]
}
walls_length = {
"wall1": 5,
"wall2": 5,
"wall3": 5
}
max_distance, left_corner, right_corner, wall = self.calculator.free_space_algorithm(objects, walls, walls_length)
self.assertAlmostEqual(max_distance, 4.24264069)
self.assertAlmostEqual(left_corner, (2, 2))
self.assertAlmostEqual(right_corner, (3, 3))
self.assertEqual(wall, "wall2")