Example #1
0
    def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color), colors['huslp'])
Example #2
0
    def test_snapshot(self):
        for h in range(37):
            for s in range(21):
                for l in range(21):
                    H = h * 10.0
                    S = s * 5.0
                    L = l * 5.0

                    test = husl.husl_to_hex(H, S, L)
                    correct = self.snapshot['husl'][h][s][l]
                    self.assertEqual(test, correct)
                    test2 = husl.husl_to_hex(*husl.hex_to_husl(correct))
                    self.assertEqual(test2, correct)

                    test = husl.huslp_to_hex(H, S, L)
                    correct = self.snapshot['huslp'][h][s][l]
                    self.assertEqual(test, correct)
                    test2 = husl.huslp_to_hex(*husl.hex_to_huslp(correct))
                    self.assertEqual(test2, correct)
Example #3
0
    def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color),
                                   colors['huslp'])