diff --git a/conntrackt/tests/test_utils.py b/conntrackt/tests/test_utils.py --- a/conntrackt/tests/test_utils.py +++ b/conntrackt/tests/test_utils.py @@ -139,6 +139,23 @@ class GetDistinctColorsTest(TestCase): equal = abs(colors[0].hsl["h"] + 1 - colors[12].hsl["h"] - reference) < delta self.assertEqual(True, equal) + def test_zero_count(self): + """ + Tests if an empty list is returned in case the requested count is 0. + """ + + colors = utils.get_distinct_colors(0) + + self.assertIsInstance(colors, list) + self.assertEqual(len(colors), 0) + + def test_negative_count(self): + """ + Tests if proper exception is raised in case a negative count is passed. + """ + + self.assertRaisesRegexp(ValueError, "^Count must be a non-negative integer value\.$", utils.get_distinct_colors, -10) + class GenerateProjectDiagramTest(TestCase): """ diff --git a/conntrackt/utils.py b/conntrackt/utils.py --- a/conntrackt/utils.py +++ b/conntrackt/utils.py @@ -104,6 +104,12 @@ def get_distinct_colors(count, start=pal List of distinct palette.Color instances. """ + # If zero is passed as count, return empty list. + if count == 0: + return [] + elif count < 0: + raise ValueError("Count must be a non-negative integer value.") + # Read the HSL from provided Color. hue, sat, lum = start.hsl["h"], start.hsl["s"], start.hsl["l"]