-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_test.go
83 lines (63 loc) · 2.07 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
package camalian
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuild(t *testing.T) {
c := new(Color).Build(10, 20, 30, false)
assert.Equal(t, c.R, uint8(10))
assert.Equal(t, c.G, uint8(20))
assert.Equal(t, c.B, uint8(30))
assert.Equal(t, c.HSL, HSL{})
assert.Equal(t, c.HSV, HSV{})
}
func TestBuildWihComponets(t *testing.T) {
c := new(Color).Build(10, 20, 30, true)
assert.Equal(t, c.R, uint8(10))
assert.Equal(t, c.G, uint8(20))
assert.Equal(t, c.B, uint8(30))
assert.Equal(t, c.HSL, HSL{H: 210, S: 50, L: 7.8431377})
assert.Equal(t, c.HSV, HSV{H: 210, S: 66.666664, V: 11.764706})
}
func TestBuildFromHex(t *testing.T) {
c, _ := new(Color).BuildFromHex("#0a141e", false)
assert.Equal(t, c.R, uint8(10))
assert.Equal(t, c.G, uint8(20))
assert.Equal(t, c.B, uint8(30))
assert.Equal(t, c.HSL, HSL{})
assert.Equal(t, c.HSV, HSV{})
}
func TestBuildFromHexWithComponents(t *testing.T) {
c, _ := new(Color).BuildFromHex("#0a141e", true)
assert.Equal(t, c.R, uint8(10))
assert.Equal(t, c.G, uint8(20))
assert.Equal(t, c.B, uint8(30))
assert.Equal(t, c.HSL, HSL{H: 210, S: 50, L: 7.8431377})
assert.Equal(t, c.HSV, HSV{H: 210, S: 66.666664, V: 11.764706})
}
func TestBuildFromHexWithoutHash(t *testing.T) {
c, _ := new(Color).BuildFromHex("0a141e", false)
assert.Equal(t, c.R, uint8(10))
assert.Equal(t, c.G, uint8(20))
assert.Equal(t, c.B, uint8(30))
}
func TestBuildFromHexWithInvalidHash(t *testing.T) {
_, e := new(Color).BuildFromHex("#0ag41e", false)
assert.Error(t, e)
}
func TestRgbDistance(t *testing.T) {
c1, _ := new(Color).BuildFromHex("#0a241e", false)
c2, _ := new(Color).BuildFromHex("#0a142e", false)
rgbDistance := c1.RgbDistance(c2)
assert.Equal(t, 22.627416997969522, rgbDistance)
}
func TestHuDistance(t *testing.T) {
c1, _ := new(Color).BuildFromHex("#0a241e", true)
c2, _ := new(Color).BuildFromHex("#0a142e", true)
hueDistance := c1.HueDistance(c2)
assert.Equal(t, hueDistance, uint16(57))
}
func TestToHex(t *testing.T) {
c1, _ := new(Color).BuildFromHex("#ff0005", false)
assert.Equal(t, c1.ToHex(), "#FF0005")
}