-
Notifications
You must be signed in to change notification settings - Fork 26
/
hsva_test.go
81 lines (62 loc) · 2.32 KB
/
hsva_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
package captcha
import (
"fmt"
"image/color"
"testing"
)
func TestHSVAInterface(t *testing.T) {
var _ color.Color = hsva{}
}
func TestConversionGray(t *testing.T) {
var white1 color.Color = hsva{h: 0.0, s: 0.0, v: 1.0, a: uint8(255)}
var white2 color.Color = color.RGBA{R: uint8(255), G: uint8(255), B: uint8(255), A: uint8(255)}
if err := eq(white1, white2); err != nil {
t.Fatal(err)
}
var black1 color.Color = hsva{h: 0.0, s: 0.0, v: 0.0, a: uint8(255)}
var black2 color.Color = color.RGBA{R: uint8(0), G: uint8(0), B: uint8(0), A: uint8(255)}
if err := eq(black1, black2); err != nil {
t.Fatal(err)
}
var gray1 color.Color = hsva{h: 1.0, s: 0.0, v: 0.8, a: uint8(255)}
var gray2 color.Color = color.RGBA{R: uint8(204), G: uint8(204), B: uint8(204), A: uint8(255)}
if err := eq(gray1, gray2); err != nil {
t.Fatal(err)
}
}
func TestConversionRGB(t *testing.T) {
var yellow1 color.Color = hsva{h: 60.0 / 360.0, s: 0.6, v: 1.0, a: uint8(255)}
var yellow2 color.Color = color.RGBA{R: uint8(255), G: uint8(255), B: uint8(102), A: uint8(255)}
if err := eq(yellow1, yellow2); err != nil {
t.Fatal(err)
}
var green1 color.Color = hsva{h: 120.0 / 360.0, s: 1.0, v: 0.8, a: uint8(255)}
var green2 color.Color = color.RGBA{R: uint8(0), G: uint8(204), B: uint8(0), A: uint8(255)}
if err := eq(green1, green2); err != nil {
t.Fatal(err)
}
var teal1 color.Color = hsva{h: 180.0 / 360.0, s: 0.5, v: 0.8, a: uint8(255)}
var teal2 color.Color = color.RGBA{R: uint8(102), G: uint8(204), B: uint8(204), A: uint8(255)}
if err := eq(teal1, teal2); err != nil {
t.Fatal(err)
}
var blue1 color.Color = hsva{h: 240.0 / 360.0, s: 0.75, v: 0.8, a: uint8(255)}
var blue2 color.Color = color.RGBA{R: uint8(51), G: uint8(51), B: uint8(204), A: uint8(255)}
if err := eq(blue1, blue2); err != nil {
t.Fatal(err)
}
var pink1 color.Color = hsva{h: 300.0 / 360.0, s: 0.2, v: 1.0, a: uint8(255)}
var pink2 color.Color = color.RGBA{R: uint8(255), G: uint8(204), B: uint8(255), A: uint8(255)}
if err := eq(pink1, pink2); err != nil {
t.Fatal(err)
}
}
func eq(c0, c1 color.Color) error {
r0, g0, b0, a0 := c0.RGBA()
r1, g1, b1, a1 := c1.RGBA()
if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
return fmt.Errorf("got 0x%04x 0x%04x 0x%04x 0x%04x\nwant 0x%04x 0x%04x 0x%04x 0x%04x",
r0, g0, b0, a0, r1, g1, b1, a1)
}
return nil
}