Esempio n. 1
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, ' ')
Esempio n. 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')
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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')