-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshades_test.go
79 lines (59 loc) · 1.43 KB
/
shades_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
package color_test
import (
"math/rand"
"testing"
"github.com/shelepuginivan/color"
"github.com/stretchr/testify/assert"
)
func TestShades(t *testing.T) {
for range 1000 {
var (
h = rand.Intn(360)
s = rand.Intn(101)
l = rand.Intn(101)
n = 2 + rand.Intn(29)
c = &color.HSL{h, s, l}
)
shades := color.Shades(c, n)
assert.Equal(t, c.HSL(), shades[0])
assert.Equal(t, &color.RGB{0, 0, 0}, shades[n-1].RGB())
contrastToBlack := make([]float64, n)
for i, shade := range shades {
contrastToBlack[i] = color.Contrast(shade, &color.RGB{0, 0, 0})
}
assert.IsNonIncreasing(t, contrastToBlack)
}
}
func TestTints(t *testing.T) {
for range 1000 {
var (
h = rand.Intn(360)
s = rand.Intn(101)
l = rand.Intn(101)
n = 2 + rand.Intn(29)
c = &color.HSL{h, s, l}
)
tints := color.Tints(c, n)
assert.Equal(t, c.HSL(), tints[0])
assert.Equal(t, &color.RGB{255, 255, 255}, tints[n-1].RGB())
contrastToWhite := make([]float64, n)
for i, tint := range tints {
contrastToWhite[i] = color.Contrast(tint, &color.RGB{255, 255, 255})
}
assert.IsNonIncreasing(t, contrastToWhite)
}
}
func TestTones(t *testing.T) {
for range 1000 {
var (
h = rand.Intn(360)
s = rand.Intn(101)
l = rand.Intn(101)
n = 2 + rand.Intn(29)
c = &color.HSL{h, s, l}
)
tones := color.Tones(c, n)
assert.Equal(t, c.HSL(), tones[0])
assert.Equal(t, &color.RGB{128, 128, 128}, tones[n-1].RGB())
}
}