more tests

This commit is contained in:
John Cupitt 2014-09-14 21:30:27 +01:00
parent d14a6ea2c7
commit 876a7538af
2 changed files with 48 additions and 0 deletions

6
TODO
View File

@ -1,6 +1,12 @@
- python:
- this is very annoying:
real = im.complexget(Vips.OperationComplexget.REAL)
define im.real() and im.imag()
- could import like this:
from gi.repository import Vips

View File

@ -264,5 +264,47 @@ class TestArithmetic(unittest.TestCase):
# test the rest of VipsArithmetic
def test_avg(self):
im = Vips.Image.black(50, 100)
test = im.insert(im + 100, 50, 0, expand = True)
test.write_to_file("x.v")
for fmt in all_formats:
self.assertAlmostEqual(test.cast(fmt).avg(), 50)
def test_polar(self):
im = Vips.Image.black(100, 100) + 100
im = im.complexform(im)
im = im.complex(Vips.OperationComplex.POLAR)
real = im.complexget(Vips.OperationComplexget.REAL)
self.assertAlmostEqual(real.avg(), 100 * 2 ** 0.5)
imag = im.complexget(Vips.OperationComplexget.IMAG)
self.assertAlmostEqual(imag.avg(), 45)
def test_rect(self):
im = Vips.Image.black(100, 100)
im = (im + 100 * 2 ** 0.5).complexform(im + 45)
im = im.complex(Vips.OperationComplex.RECT)
real = im.complexget(Vips.OperationComplexget.REAL)
self.assertAlmostEqual(real.avg(), 100)
imag = im.complexget(Vips.OperationComplexget.IMAG)
self.assertAlmostEqual(imag.avg(), 100)
def test_conjugate(self):
im = Vips.Image.black(100, 100) + 100
im = im.complexform(im)
im = im.complex(Vips.OperationComplex.CONJ)
real = im.complexget(Vips.OperationComplexget.REAL)
self.assertAlmostEqual(real.avg(), 100)
imag = im.complexget(Vips.OperationComplexget.IMAG)
self.assertAlmostEqual(imag.avg(), -100)
if __name__ == '__main__':
unittest.main()