106 lines
2.7 KiB
Python
106 lines
2.7 KiB
Python
"""test of core functions """
|
|
|
|
import floatimg
|
|
|
|
|
|
def test_create():
|
|
width = 640
|
|
height = 480
|
|
img = floatimg.create(width, height, floatimg.RGB)
|
|
assert img.width == width
|
|
assert img.height == height
|
|
assert img.type_id == floatimg.RGB
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
assert img.type_id == floatimg.RGB
|
|
# TODO inspect RVB
|
|
|
|
|
|
def test_clone():
|
|
width = 5
|
|
height = 5
|
|
img = floatimg.create(width, height, floatimg.RGB)
|
|
img.rgb_constant(127.0, 127.0, 127.0)
|
|
|
|
# clone without copying pixel values
|
|
img2 = img.clone()
|
|
assert img.width == img2.width
|
|
assert img.height == img2.height
|
|
assert img.type_id == img2.type_id
|
|
# TODO inspect RVB and do pixel per pixel comparison
|
|
for y in range(height):
|
|
for x in range(width):
|
|
assert img.get_rgb(x, y) != img2.get_rgb(x, y)
|
|
|
|
img2 = img.clone(1)
|
|
assert img.width == img2.width
|
|
assert img.height == img2.height
|
|
assert img.type_id == img2.type_id
|
|
# TODO inspect RVB and do pixel per pixel comparison
|
|
for y in range(height):
|
|
for x in range(width):
|
|
assert img.get_rgb(x, y) == img2.get_rgb(x, y)
|
|
|
|
|
|
def test_rgb_constant():
|
|
width = 5
|
|
height = 5
|
|
color = [127.0, 127.0, 127.0]
|
|
img = floatimg.create_rgb(width, height)
|
|
img.rgb_constant(*color)
|
|
for y in range(height):
|
|
for x in range(width):
|
|
assert img.get_rgb(x, y) == color
|
|
|
|
|
|
def test_copy_data():
|
|
width = 5
|
|
height = 5
|
|
color = [127.0, 127.0, 127.0]
|
|
img = floatimg.create_rgb(width, height)
|
|
img.rgb_constant(*color)
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
img2.rgb_constant(64.0, 64.0, 64.0)
|
|
|
|
img.copy_data(img2)
|
|
|
|
for y in range(height):
|
|
for x in range(width):
|
|
assert img.get_rgb(x, y) == img2.get_rgb(x, y)
|
|
|
|
|
|
def test_clear():
|
|
width, height = 5, 5
|
|
color = [127.0, 127.0, 127.0]
|
|
img = floatimg.create_rgb(width, height)
|
|
img.rgb_constant(*color)
|
|
img.clear()
|
|
for y in range(height):
|
|
for x in range(width):
|
|
assert img.get_rgb(x, y) == [0.0, 0.0, 0.0]
|
|
|
|
|
|
def test_str_type():
|
|
width, height = 5, 5
|
|
img = floatimg.create_rgb(width, height)
|
|
assert img.str_type == "rgb"
|
|
|
|
|
|
def test__str__():
|
|
width, height = 5, 5
|
|
img = floatimg.create_rgb(width, height)
|
|
img_str = str(img)
|
|
assert " width=5 " in img_str
|
|
assert " height=5 " in img_str
|
|
assert " type=rgb>" in img_str
|
|
|
|
|
|
def test_put_rgb():
|
|
width, height = 5, 5
|
|
img = floatimg.create_rgb(width, height)
|
|
assert img.get_rgb(0, 0) == [0.0, 0.0, 0.0]
|
|
img.put_rgb(0, 0, [127.0, 127.0, 127.0])
|
|
assert img.get_rgb(0, 0) == [127.0, 127.0, 127.0]
|