Re-roll in case of identical noise

This commit is contained in:
Hugo 2017-12-19 15:06:43 +02:00
parent 2cb6523899
commit c8eebc1dc7

View File

@ -347,14 +347,24 @@ class TestImage(PillowTestCase):
# Arrange # Arrange
size = (100, 100) size = (100, 100)
sigma = 128 sigma = 128
# To reduce chance of randomly having the same value twice
attempts = 5
# Act # Act
im = Image.effect_noise(size, sigma) while attempts > 0:
im = Image.effect_noise(size, sigma)
# Assert # Assert
self.assertEqual(im.size, (100, 100)) self.assertEqual(im.size, (100, 100))
self.assertEqual(im.mode, "L") self.assertEqual(im.mode, "L")
self.assertNotEqual(im.getpixel((0, 0)), im.getpixel((0, 1))) p0 = im.getpixel((0, 0))
p1 = im.getpixel((0, 1))
if p0 == p1:
# Let's roll again
attempts -= 1
else:
break
self.assertNotEqual(p0, p1)
def test_effect_spread(self): def test_effect_spread(self):
# Arrange # Arrange