small bugs, start unit tests

This commit is contained in:
John Cupitt 2014-09-11 21:54:52 +01:00
parent 62a98dbdf7
commit 62c73d5109
5 changed files with 1099 additions and 5 deletions

View File

@ -380,6 +380,3 @@
fun:rb_enc_str_new
}

1037
python/atith.log Normal file

File diff suppressed because it is too large Load Diff

41
python/test_arithmetic.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import unittest
#import logging
#logging.basicConfig(level = logging.DEBUG)
from gi.repository import Vips
from vips8 import vips
formats = [Vips.BandFormat.UCHAR,
Vips.BandFormat.CHAR,
Vips.BandFormat.USHORT,
Vips.BandFormat.SHORT,
Vips.BandFormat.UINT,
Vips.BandFormat.INT,
Vips.BandFormat.FLOAT,
Vips.BandFormat.DOUBLE,
Vips.BandFormat.COMPLEX,
Vips.BandFormat.DPCOMPLEX]
class TestArithmetic(unittest.TestCase):
def setUp(self):
black = Vips.Image.black(100, 100)
mono = black.draw_circle(128, 50, 50, 50)
colour = Vips.Image.bandjoin([black, mono, black])
images = [black, mono, colour]
self.test_set = [x.cast(y) for x in images for y in formats]
self.avgs = [x.avg() for x in self.test_set]
def test_addconst(self):
def add12(x):
return x + 12
self.assertEqual([add12(x).avg for x in self.test_set],
[add12(x) for x in self.avgs])
if __name__ == '__main__':
unittest.main()

View File

@ -10,8 +10,27 @@ from vips8 import vips
a = Vips.Image.new_from_file(sys.argv[1])
def should_equal(test, a, b):
if abs(a - b) > 0.01:
print '%s: seen %g and %g' % (test, a, b)
sys.exit(1)
def bandsplit(a):
return [a.extract_band(i) for i in range(0, a.bands)]
# test operator overloads
# addition
b = a + 12
should_equal('add constant', a.avg() + 12, b.avg())
b = a + [12, 0, 0]
x = map (lambda x: x.avg()) bandsplit(a)
y = map (lambda x: x.avg()) bandsplit(b)
x[0] += 12
should_equal('add multiband constant', sum(x), sum(y))
b = a + [12, 0, 0]
b = a + b
b = 12 + a

View File

@ -323,7 +323,7 @@ def vips_rdiv(self, other):
return (self ** -1) * other
def vips_floor(self):
self.round(Vips.OperationRound.FLOOR)
return self.round(Vips.OperationRound.FLOOR)
def vips_floordiv(self, other):
if isinstance(other, Vips.Image):
@ -454,7 +454,7 @@ Vips.Image.__rmul__ = vips_mul
Vips.Image.__div__ = vips_div
Vips.Image.__rdiv__ = vips_rdiv
Vips.Image.__floordiv__ = vips_floordiv
Vips.Image.__rfloordiv__ = vips_floordiv
Vips.Image.__rfloordiv__ = vips_rfloordiv
Vips.Image.__mod__ = vips_mod
Vips.Image.__pow__ = vips_pow
Vips.Image.__rpow__ = vips_rpow