def test_convert_to_point_list_down(self):
     step = st.Step(3, DOWN)
     act_point, point_list = step.convert_to_point_list(self.start)
     self.assertEqual(
         point_list,
         [p.Point(0, 0), p.Point(0, 1),
          p.Point(0, 2)])
     self.assertEqual(act_point, p.Point(0, 3))
 def test_convert_to_point_list_up(self):
     step = st.Step(3, UP)
     act_point, point_list = step.convert_to_point_list(self.start)
     self.assertEqual(
         point_list,
         [p.Point(0, 0), p.Point(0, -1),
          p.Point(0, -2)])
     self.assertEqual(act_point, p.Point(0, -3))
 def test_convert_to_point_list_left(self):
     step = st.Step(3, LEFT)
     act_point, point_list = step.convert_to_point_list(self.start)
     self.assertEqual(
         point_list,
         [p.Point(0, 0), p.Point(-1, 0),
          p.Point(-2, 0)])
     self.assertEqual(act_point, p.Point(-3, 0))
 def test_convert_to_point_list_right(self):
     step = st.Step(3, RIGHT)
     act_point, point_list = step.convert_to_point_list(self.start)
     self.assertEqual(
         point_list,
         [p.Point(0, 0), p.Point(1, 0),
          p.Point(2, 0)])
     self.assertEqual(act_point, p.Point(3, 0))
def get_data_from_text_file(file_path):
    list_of_points = []     # [(Point1, Point2), (Point1, Point2), ...]

    with open(file_path) as f:
        lines = f.read().split("\n")
        dim = lines[0].split(";")
        dimensions = (int(dim[0]), int(dim[1]))
        lines.pop(0)
        lines.pop(-1)

        for l in lines:
            x1, y1, x2, y2 = l.split(";")
            p1 = point.Point(int(x1), int(y1))
            p2 = point.Point(int(x2), int(y2))
            list_of_points.append((p1, p2))

    return dimensions, list_of_points
Esempio n. 6
0
def go_n_moves_in_direction(direction, length, actual_position, stop):
    x_coord = actual_position.x_coord
    y_coord = actual_position.y_coord

    stop_xy_coord = (stop.x_coord, stop.y_coord)

    for i in range(length):
        if (x_coord, y_coord) != stop_xy_coord:
            if direction == RIGHT:
                x_coord += 1
            elif direction == LEFT:
                x_coord -= 1
            elif direction == UP:
                y_coord -= 1
            elif direction == DOWN:
                y_coord += 1
        else:
            return i, p.Point(x_coord, y_coord)
    return length, p.Point(x_coord, y_coord)
    def test_mutation_7(self):
        sol = s.Solution()
        path1 = pa.Path(self.start)
        path1.step_list = [st.Step(5, LEFT), st.Step(4, UP), st.Step(1, LEFT)]
        path2 = pa.Path(pt.Point(2, 1))
        path2.step_list = [
            st.Step(2, RIGHT),
            st.Step(1, DOWN),
            st.Step(3, RIGHT)
        ]
        sol.path_list = [path1, path2]

        v.draw_plots(sol.parse_to_list_of_points(), (10, 10))
        op.mutation(sol)
        v.draw_plots(sol.parse_to_list_of_points(), (10, 10))
Esempio n. 8
0
    def test_convert_to_point_list(self):
        start = pt.Point(3, 4)
        p_list = [
            pt.Point(3, 4),
            pt.Point(2, 4),
            pt.Point(1, 4),
            pt.Point(0, 4),
            pt.Point(-1, 4),
            pt.Point(-2, 4),
            pt.Point(-2, 3),
            pt.Point(-2, 2),
            pt.Point(-2, 1),
            pt.Point(-2, 0),
            pt.Point(-1, 0)
        ]

        path = pa.Path(start)
        path.step_list = self.step_list
        point_list = path.convert_point_list()
        self.assertEqual(point_list, p_list)
 def setUp(self):
     self.start = pt.Point(9, 7)
     self.solution = s.Solution()
     self.path = pa.Path(self.start)
     self.path_before_mut = pa.Path(pt.Point(9, 7))
 def setUp(self):
     self.start = p.Point(0, 0)