operator binding

This commit is contained in:
2021-05-14 06:40:38 +02:00
parent eaf039a83f
commit 95c1e6d9c6
5 changed files with 178 additions and 14 deletions

View File

@@ -112,3 +112,67 @@ def test_add():
img.put(0, 0, color)
img.add(0, 0, color)
assert img.get(0, 0) == [64.0, 64.0, 64.0]
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]