def test_compose_key_function(self): hsl = Color.from_hsl((20, 80, 50)) rgb = Color((10, 165, 70)) hsl_func = sorter.compile_color_sort_key_function('lHs') rgb_func = sorter.compile_color_sort_key_function('bRG') key_func = sorter.compose_key_function(hsl_func) for k, h in zip(key_func(hsl), (50, -20, 80)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compose_key_function(hsl_func, operator.itemgetter(0)) for k, h in zip(key_func([hsl]), (50, -20, 80)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compose_key_function(rgb_func) for k, h in zip(key_func(rgb), (70, -10, -165)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compose_key_function(rgb_func, operator.itemgetter(0)) for k, h in zip(key_func([rgb]), (70, -10, -165)): self.assertAlmostEqual(k, h, 0)
def test_compile_color_sort_key_function(self): hsl = Color.from_hsl((20, 80, 50)) rgb = Color((10, 165, 70)) key_func = sorter.compile_color_sort_key_function('hsl') for k, h in zip(key_func(hsl), (20, 80, 50)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compile_color_sort_key_function('HSL') for k, h in zip(key_func(hsl), (-20, -80, -50)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compile_color_sort_key_function('lHs') for k, h in zip(key_func(hsl), (50, -20, 80)): self.assertAlmostEqual(k, h, 0) key_func = sorter.compile_color_sort_key_function('rgb') for k, h in zip(key_func(rgb), (10, 165, 70)): self.assertEqual(k, h, 0) key_func = sorter.compile_color_sort_key_function('bRG') for k, h in zip(key_func(rgb), (70, -10, -165)): self.assertEqual(k, h, 0)
def test_from_hsl(self): self.assertEqual(Color.from_hsl((60, 100, 50)).hex, '#ffff00') self.assertEqual(Color.from_hsl((60.0, 100.0, 50.0)).hex, '#ffff00') self.assertEqual(Color.from_hsl((30, 100, 50)).hex, '#ff8000') self.assertEqual(Color.from_hsl((30.0, 100.0, 50.0)).hex, '#ff8000')