add tests

This commit is contained in:
John Cupitt 2019-08-19 16:27:44 +01:00
parent daf578ca42
commit 2d0c21279a
3 changed files with 41 additions and 0 deletions

View File

@ -8,6 +8,7 @@
- support webp and zstd compression in tiff
- loaders use "minimise" to close input files earlier
- integrate support for oss-fuzz [omira-sch]
- add vips_switch() / vips_case() ... fast many-way ifthenelse
9/7/19 started 8.8.2
- better early shutdown in readers

View File

@ -539,6 +539,27 @@ class TestConversion:
result = r(50, 50)
assert_almost_equal_objects(result, [3.0, 4.9, 6.9], threshold=0.1)
def test_switch(self):
x = pyvips.Image.grey(256, 256, uchar=True)
# slice into two at 128, we should get 50% of pixels in each half
index = pyvips.Image.switch([x < 128, x >= 128])
assert index.avg() == 0.5
# slice into four
index = pyvips.Image.switch([
x < 64,
x >= 64 and x < 128,
x >= 128 and x < 192,
x >= 192
])
assert index.avg() == 1.5
# no match should return n + 1
# FIXME uncomment when we fix relational const
#index = pyvips.Image.switch([x == 1000, x == 2000])
#assert index.avg() == 2
def test_insert(self):
for x in all_formats:
for y in all_formats:

View File

@ -109,6 +109,25 @@ class TestHistogram:
# new mean should be closer to target mean
assert abs(im.avg() - 128) > abs(im2.avg() - 128)
def test_case(self):
# slice into two at 128, we should get 50% of pixels in each half
x = pyvips.Image.grey(256, 256, uchar=True)
index = pyvips.Image.switch([x < 128, x >= 128])
y = index.case([10, 20])
assert y.avg() == 15
# slice into four
index = pyvips.Image.switch([
x < 64,
x >= 64 and x < 128,
x >= 128 and x < 192,
x >= 192
])
assert index.case([10, 20, 30, 40]).avg() == 25
# values over N should use the last value
assert index.case([10, 20, 30]).avg() == 22.5
if __name__ == '__main__':
pytest.main()