diff -r 2f4c4db9aee5 Lib/test/test_colorsys.py --- a/Lib/test/test_colorsys.py Thu Jul 25 17:36:15 2013 -0400 +++ b/Lib/test/test_colorsys.py Sat Jul 27 00:21:21 2013 +0800 @@ -11,9 +11,9 @@ def assertTripleEqual(self, tr1, tr2): self.assertEqual(len(tr1), 3) self.assertEqual(len(tr2), 3) - self.assertAlmostEqual(tr1[0], tr2[0]) - self.assertAlmostEqual(tr1[1], tr2[1]) - self.assertAlmostEqual(tr1[2], tr2[2]) + self.assertAlmostEqual(tr1[0], tr2[0], 5) + self.assertAlmostEqual(tr1[1], tr2[1], 5) + self.assertAlmostEqual(tr1[2], tr2[2], 5) def test_hsv_roundtrip(self): for r in frange(0.0, 1.0, 0.2): @@ -69,6 +69,33 @@ self.assertTripleEqual(hls, colorsys.rgb_to_hls(*rgb)) self.assertTripleEqual(rgb, colorsys.hls_to_rgb(*hls)) + def test_yiq_roundtrip(self): + for r in frange(0.0, 1.0, 0.2): + for g in frange(0.0, 1.0, 0.2): + for b in frange(0.0, 1.0, 0.2): + rgb = (r, g, b) + self.assertTripleEqual( + rgb, + colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb)) + ) + + def test_yiq_values(self): + values = [ + # rgb, yiq + ((0.0, 0.0, 0.0), (0 , 0.0 , 0.0 )), # black + ((0.0, 0.0, 1.0), (0.11, -0.32, 0.31)), # blue + ((0.0, 1.0, 0.0), (0.59, -0.28, -0.52)), # green + ((0.0, 1.0, 1.0), (0.7 , -0.6 , -0.21)), # cyan + ((1.0, 0.0, 0.0), (0.3 , 0.6 , 0.21)), # red + ((1.0, 0.0, 1.0), (0.41, 0.28, 0.52)), # purple + ((1.0, 1.0, 0.0), (0.89, 0.32, -0.31)), # yellow + ((1.0, 1.0, 1.0), (1.0 , -0.0 , -0.0 )), # white + ((0.5, 0.5, 0.5), (0.5 , -0.0 , -0.0 )), # grey + ] + for (rgb, yiq) in values: + self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb)) + self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq)) + def test_main(): test.support.run_unittest(ColorsysTest)