Пример #1
0
def test_canvas_undo_draw_line():
    canvas = Canvas(10, 10)
    line1 = Line(Point(0, 2), Point(9, 2))
    canvas.draw_line(line1)
    expected_cells_after_undo = deepcopy(canvas.cells)
    line2 = Line(Point(0, 5), Point(9, 5))
    canvas.draw_line(line2)
    canvas.undo()
    assert canvas.cells == expected_cells_after_undo
Пример #2
0
def test_canvas_draw_line_vertical():
    canvas = Canvas(50, 50)
    from_point = Point(3, 3)
    to_point = Point(3, 35)
    line = Line(from_point, to_point)
    canvas.draw_line(line)
    for point in line.get_points():
        assert canvas.cells[point.x][point.y] == (CanvasCellContentType.Line,
                                                  'x')
Пример #3
0
def test_line_get_points_for_vertical_line():
    from_point = Point(1, 1)
    to_point = Point(5, 1)
    expected_points = [
        from_point,
        Point(2, 1),
        Point(3, 1),
        Point(4, 1), to_point
    ]
    line = Line(from_point, to_point)
    points = line.get_points()
    assert points == expected_points
Пример #4
0
def test_line_get_points_for_horizontal_line():
    from_point = Point(1, 1)
    to_point = Point(1, 5)
    expected_points = [
        from_point,
        Point(1, 2),
        Point(1, 3),
        Point(1, 4), to_point
    ]
    line = Line(from_point, to_point)
    points = line.get_points()
    assert points == expected_points
Пример #5
0
def test_canvas_draw_line_fails_when_a_point_is_out_of_bounds():
    canvas = Canvas(50, 50)
    from_point1 = Point(3, 3)
    to_point1 = Point(3, 350)
    line1 = Line(from_point1, to_point1)
    with pytest.raises(OutOfCanvasBoundError):
        canvas.draw_line(line1)

    from_point2 = Point(3, 300)
    to_point2 = Point(3, 35)
    line2 = Line(from_point2, to_point2)
    with pytest.raises(OutOfCanvasBoundError):
        canvas.draw_line(line2)
Пример #6
0
def test_rectangle_get_lines():
    top_right = Point(1, 1)
    top_left = Point(5, 1)
    bottom_left = Point(5, 5)
    bottom_right = Point(1, 5)
    rectangle = Rectangle(top_left, bottom_right)
    expected_lines = [
        Line(top_left, top_right),
        Line(top_left, bottom_left),
        Line(top_right, bottom_right),
        Line(bottom_left, bottom_right)
    ]
    lines = rectangle.get_lines()
    assert lines == expected_lines
Пример #7
0
def test_canvas_bucket_fill_shape():
    width, height = 10, 10
    canvas = Canvas(width, height)
    line = Line(Point(0, 1), Point(9, 1))
    canvas.draw_line(line)
    canvas.bucket_fill(Point(0, 1), 'o')
    #line has been filled
    for point in line.get_points():
        assert canvas.cells[point.x][point.y] == (CanvasCellContentType.Line,
                                                  'o')
    #rest have not been filled
    for x in range(width):
        for y in range(height):
            if Point(x, y) not in line.get_points():
                assert canvas.cells[x][y] == (CanvasCellContentType.Empty, ' ')
Пример #8
0
def test_canvas_delete_shape():
    canvas = Canvas(10, 10)
    line = Line(Point(0, 1), Point(9, 1))
    expected_cells_after_delete = deepcopy(canvas.cells)
    canvas.draw_line(line)
    canvas.delete(Point(0, 1))
    assert canvas.cells == expected_cells_after_delete
Пример #9
0
def test_draw_line_command_execute():
    canvas = Mock(spec=Canvas)
    command = DrawLineCommand(lambda: canvas)
    x1, y1, x2, y2 = 1, 1, 1, 10
    line = Line(Point(x1, y1), Point(x2, y2))
    command.execute(x1, y1, x2, y2)
    canvas.draw_line.assert_called_once_with(line)
Пример #10
0
def test_canvas_undo_bucket_fill():
    canvas = Canvas(10, 10)
    line = Line(Point(0, 2), Point(9, 2))
    canvas.draw_line(line)
    expected_cells_after_undo = deepcopy(canvas.cells)
    canvas.bucket_fill(Point(0, 0), 'o')
    canvas.undo()
    assert canvas.cells == expected_cells_after_undo
Пример #11
0
def test_canvas_bucket_fill_area():
    width, height = 10, 10
    canvas = Canvas(width, height)
    line = Line(Point(0, 2), Point(9, 2))
    canvas.draw_line(line)
    canvas.bucket_fill(Point(0, 0), 'o')
    #top area have been filled
    for x in range(width):
        assert (canvas.cells[x][0] == (CanvasCellContentType.Empty, 'o')
                and canvas.cells[x][1] == (CanvasCellContentType.Empty, 'o'))
        #bottom area have not been filled
        for y in range(3, height):
            assert canvas.cells[x][y] == (CanvasCellContentType.Empty, ' ')
    #line have not been filled
    for point in line.get_points():
        assert canvas.cells[point.x][point.y] == (CanvasCellContentType.Line,
                                                  'x')
Пример #12
0
def test_canvas_undo_draw_rectangle():
    canvas = Canvas(10, 10)
    line = Line(Point(0, 2), Point(9, 2))
    canvas.draw_line(line)
    expected_cells_after_undo = deepcopy(canvas.cells)
    rectangle = Rectangle(Point(1, 1), Point(3, 3))
    canvas.draw_rectangle(rectangle)
    canvas.undo()
    assert canvas.cells == expected_cells_after_undo
Пример #13
0
def test_canvas_delete_colour():
    width, height = 10, 10
    canvas = Canvas(width, height)
    line = Line(Point(0, 1), Point(9, 1))
    canvas.draw_line(line)
    expected_cells_after_delete = deepcopy(canvas.cells)
    canvas.bucket_fill(Point(0, 0), 'o')
    canvas.delete(Point(0, 0))
    assert canvas.cells == expected_cells_after_delete
Пример #14
0
def test_canvas_str():
    expected_canvas_str = (" ----- "
                           "\n"
                           "|     |"
                           "\n"
                           "|xxxxx|"
                           "\n"
                           "|ooooo|"
                           "\n"
                           "|xxxxx|"
                           "\n"
                           "|     |"
                           "\n"
                           " ----- ")
    canvas = Canvas(5, 5)
    canvas.draw_line(Line(Point(0, 1), Point(4, 1)))
    canvas.draw_line(Line(Point(0, 3), Point(4, 3)))
    canvas.bucket_fill(Point(2, 2), 'o')
    assert str(canvas) == expected_canvas_str
Пример #15
0
    def execute(self, *args):
        #pylint: disable=invalid-name
        """
        Draw a line on the canvas

        Args:
            x1, y1, x2, y2:
            the int coordinates of (x1, y1) and (x2, y2) between which the line will be drawn
        """
        if len(args) < 4:
            raise ValueError("4 arguments expected (x1, y1, x2, y2)")
        x1, y1, x2, y2 = args[0], args[1], args[2], args[3]
        line = Line(Point(x1, y1), Point(x2, y2))
        self.get_canvas_fn().draw_line(line)
Пример #16
0
def test_line_initialize():
    point1 = Point(1, 1)
    point2 = Point(5, 1)
    line = Line(point1, point2)
    assert line.from_point == point1 and line.to_point == point2