python-FloatImg/tests/basics.py

179 lines
4.6 KiB
Python
Raw Normal View History

"""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.fill((127.0, 127.0, 127.0))
# clone without copying pixel values
img2 = img.clone(False)
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(x, y) != img2.get(x, y)
img2 = img.clone(True)
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(x, y) == img2.get(x, y)
def test_rgb_constant():
width = 5
height = 5
color = [127.0, 127.0, 127.0]
img = floatimg.create_rgb(width, height)
img.fill(color)
for y in range(height):
for x in range(width):
assert img.get(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.fill(color)
img2 = floatimg.create_rgb(width, height)
img2.fill((64.0, 64.0, 64.0))
img.copy_data(img2)
for y in range(height):
for x in range(width):
assert img.get(x, y) == img2.get(x, y)
def test_clear():
width, height = 5, 5
color = [127.0, 127.0, 127.0]
img = floatimg.create_rgb(width, height)
img.fill(color)
img.clear()
for y in range(height):
for x in range(width):
assert img.get(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(0, 0) == [0.0, 0.0, 0.0]
img.put(0, 0, (127.0, 127.0, 127.0))
assert img.get(0, 0) == [127.0, 127.0, 127.0]
2021-05-13 04:50:27 +11:00
def test_add():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
color = (32.0, 32.0, 32.0)
img.put(0, 0, color)
img.add(0, 0, color)
assert img.get(0, 0) == [64.0, 64.0, 64.0]
2021-05-14 15:40:38 +11:00
def test_op_add():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
color = (32.0, 32.0, 32.0)
img.fill(color)
img2 = floatimg.create_rgb(width, height)
img2.fill(color)
img3 = img + img2
for y in range(height):
for x in range(width):
assert img3.get(x, y) == [64.0, 64.0, 64.0]
def test_op_sub():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
color = (32.0, 32.0, 32.0)
img.fill(color)
img2 = floatimg.create_rgb(width, height)
img2.fill(color)
img3 = img - img2
for y in range(height):
for x in range(width):
assert img3.get(x, y) == [0.0, 0.0, 0.0]
def test_op_mul():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
color = (32.0, 32.0, 32.0)
img.fill(color)
img2 = floatimg.create_rgb(width, height)
img2.fill((2.0, 2.0, 2.0))
img3 = img * img2
for y in range(height):
for x in range(width):
assert img3.get(x, y) == [64.0, 64.0, 64.0]
def test_op_min():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
img.fill((32.0, 0.0, 32.0))
img2 = floatimg.create_rgb(width, height)
img2.fill((0.0, 32.0, 0.0))
img3 = img.min(img2)
for y in range(height):
for x in range(width):
assert img3.get(x, y) == [0.0, 0.0, 0.0]
def test_op_max():
width, height = 5, 5
img = floatimg.create_rgb(width, height)
img.fill((32.0, 0.0, 32.0))
img2 = floatimg.create_rgb(width, height)
img2.fill((0.0, 32.0, 0.0))
img3 = img.max(img2)
for y in range(height):
for x in range(width):
assert img3.get(x, y) == [32.0, 32.0, 32.0]