-
Notifications
You must be signed in to change notification settings - Fork 6
/
color_test.go
92 lines (85 loc) · 1.46 KB
/
color_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package lifxlan_test
import (
"image/color"
"reflect"
"testing"
"go.yhsif.com/lifxlan"
)
const kelvin = lifxlan.KelvinCool
func TestFromColor(t *testing.T) {
type testCase struct {
Label string
Color color.Color
Expected lifxlan.Color
}
cases := []testCase{
{
Label: "Black",
Color: color.Black,
Expected: lifxlan.Color{
Hue: 0,
Saturation: 0,
Brightness: 0,
},
},
{
Label: "White",
Color: color.White,
Expected: lifxlan.Color{
Hue: 0,
Saturation: 0,
Brightness: 65535,
},
},
{
Label: "Red",
Color: &color.RGBA{
R: 0xff,
},
Expected: lifxlan.Color{
Hue: 0,
Saturation: 65535,
Brightness: 65535,
},
},
{
Label: "Green",
Color: &color.RGBA{
G: 0xff,
},
Expected: lifxlan.Color{
Hue: 21845,
Saturation: 65535,
Brightness: 65535,
},
},
{
Label: "Blue",
Color: &color.RGBA{
B: 0xff,
},
Expected: lifxlan.Color{
Hue: 43691,
Saturation: 65535,
Brightness: 65535,
},
},
}
for _, test := range cases {
t.Run(
test.Label,
func(t *testing.T) {
expected := test.Expected
expected.Kelvin = kelvin
got := *lifxlan.FromColor(test.Color, kelvin)
if !reflect.DeepEqual(got, expected) {
r, g, b, a := test.Color.RGBA()
t.Errorf(
"{r:%04x, g:%04x, b:%04x, a:%04x} expected %+v, got %+v",
r, g, b, a, expected, got,
)
}
},
)
}
}