From d26096103618e02ebf8038b11fc1b2eb9da6dc2d Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Thu, 19 Aug 2021 11:49:06 +0200 Subject: [PATCH] Test that QgsRandomColorRamp returns distinct colors --- tests/src/python/test_qgscolorramp.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/src/python/test_qgscolorramp.py b/tests/src/python/test_qgscolorramp.py index 902da36f706c..5ed05eadb39a 100644 --- a/tests/src/python/test_qgscolorramp.py +++ b/tests/src/python/test_qgscolorramp.py @@ -288,11 +288,14 @@ def testQgsRandomColorRamp(self): self.assertEqual(cloned.type(), 'randomcolors') # test with pregenerated colors - for i in range(10000): - r.setTotalColorCount(10) - for j in range(10): - c = r.color(j * 0.1) + for n in range(2, 100): + r.setTotalColorCount(n) + seen = set() + for j in range(n): + c = r.color(j / (n - 1)) self.assertTrue(c.isValid()) + seen.add(c.rgb()) + self.assertEqual(len(seen), n) def testQgsPresetSchemeColorRamp(self): # test preset color ramp