Example #1
0
def blank_image(x: int, y: int, max_level: int = 100) -> Image:
    pixel_values = [[GrayPixel(max_level) for _ in range(x)] for _ in range(y)]
    img = Image(header="P2",
                max_level=max_level,
                dimensions=(x, y),
                contents=pixel_values)
    return img
Example #2
0
def p3_image() -> Image:
    pixel_values = [[RGBPixel(0, 1, 2) for _ in range(3)] for _ in range(3)]
    img = Image(header="P3",
                max_level=255,
                dimensions=(3, 3),
                contents=pixel_values)
    return img
Example #3
0
def p2_image() -> Image:
    val = n_numbers(3 * 3)
    pixel_values = [[GrayPixel(next(val)) for _ in range(3)] for _ in range(3)]
    img = Image(header="P2",
                max_level=255,
                dimensions=(3, 3),
                contents=pixel_values)
    return img
Example #4
0
def dummy_image() -> Image:
    return Image(
        header="P2", max_level=255, dimensions=(1, 1), contents=[[GrayPixel(0)]]
    )
Example #5
0
def test_raises_valueerror_when_attempting_lighten_with_invalid_type(
        dummy_image: Image, level: int):
    with pytest.raises(ValueError):
        dummy_image.lighten(level=level)
Example #6
0
def test_raises_validationerror_when_attempting_darken_with_invalid_int(
        dummy_image: Image, level: int):
    with pytest.raises(ValidationError):
        dummy_image.darken(level=level)
Example #7
0
def test_can_execute_negative_operation(dummy_image: Image):
    negative_img = dummy_image.negative()
    assert all(val.value == 255 for row in negative_img.values for val in row)
Example #8
0
def test_can_create_empty_image():
    image = Image(header="P2", max_level=255, dimensions=(3, 3))
    assert image is not None
Example #9
0
def test_raises_exception_when_creating_image_with_invalid_dimensions(m, n):
    with pytest.raises(ValidationError):
        Image(header="P2", max_level=255, dimensions=(m, n))
Example #10
0
def test_darken_operation_respects_maximum_grayscale(dummy_image: Image):
    p = GrayPixel(100)
    dummy_image.set_pixel(1, 1, p)
    darken_img = dummy_image.darken(200)
    assert not any(val.value > 0 for row in darken_img.values for val in row)
Example #11
0
def test_lighten_operation_respects_maximum_grayscale(dummy_image: Image):
    p = GrayPixel(100)
    dummy_image.set_pixel(1, 1, p)
    ligthen_img = dummy_image.lighten(200)
    assert not any(val.value > 255 for row in ligthen_img.values
                   for val in row)
Example #12
0
def test_cannot_set_pixel_at_out_of_bounds_coordinates(dummy_image: Image,
                                                       x: int, y: int):
    p = GrayPixel(1)
    with pytest.raises(ValidationError):
        dummy_image.set_pixel(x=x, y=y, pixel=p)
Example #13
0
def test_can_set_pixel_at_valid_coordinate(dummy_image: Image):
    p = GrayPixel(1)
    dummy_image.set_pixel(x=1, y=1, pixel=p)
Example #14
0
def test_can_copy_current_image(dummy_image: Image):
    copy_image = dummy_image.copy_current_image()
    assert copy_image.x == dummy_image.x
    assert copy_image.y == dummy_image.y
    assert copy_image.values == dummy_image.values
    assert copy_image.header == dummy_image.header