OSDN Git Service

fix unittest
authorMartin Renold <martinxyz@gmx.ch>
Sun, 15 Aug 2010 08:03:40 +0000 (10:03 +0200)
committerMartin Renold <martinxyz@gmx.ch>
Sun, 15 Aug 2010 08:58:44 +0000 (10:58 +0200)
There was nothing wrong in the last commit, just too sensitive to random
dithering noise. (We should do error diffusion instead...)

tests/test_mypaintlib.py

index 03f5c8e..184cad0 100755 (executable)
@@ -8,6 +8,20 @@ sys.path.insert(0, '..')
 
 from lib import mypaintlib, tiledsurface, brush, document, command, helpers
 
+def tileConversions():
+    # fully transparent tile stays fully transparent (without noise)
+    N = mypaintlib.TILE_SIZE
+    src = zeros((N, N, 4), 'uint16')
+    dst = ones((N, N, 4), 'uint8')
+    mypaintlib.tile_convert_rgba16_to_rgba8(src, dst)
+    assert not dst.any()
+    # fully opaque tile stays fully opaque
+    src[:,:,3] = 1<<15
+    src[:,:,:3] = randint(0, 1<<15, (N, N, 3))
+    dst = zeros((N, N, 4), 'uint8')
+    mypaintlib.tile_convert_rgba16_to_rgba8(src, dst)
+    assert (dst[:,:,3] == 255).all()
+
 def directPaint():
 
     s = tiledsurface.Surface()
@@ -73,7 +87,7 @@ def pngs_equal(a, b):
         diff *= imread(a)[:,:,3:4]
     res = mean(mean(diff, 0), 0)
     print res
-    if mean(res) > 0.001:
+    if mean(res) > 0.01:
         # dithering should make this value nearly zero...
         equal = False
     print 'Maximum abs difference with premultiplied alpha (255=white): (R, G, B, A)'
@@ -188,6 +202,7 @@ from optparse import OptionParser
 parser = OptionParser('usage: %prog [options]')
 options, tests = parser.parse_args()
 
+tileConversions()
 directPaint()
 brushPaint()
 docPaint()