-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheel_test.go
205 lines (159 loc) · 3.76 KB
/
wheel_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package color_test
import (
"fmt"
"math/rand/v2"
"testing"
"github.com/shelepuginivan/color"
"github.com/shelepuginivan/color/internal/degrees"
"github.com/stretchr/testify/assert"
)
func TestComplementary(t *testing.T) {
for range 1000 {
var (
h = rand.IntN(360)
s = rand.IntN(101)
l = rand.IntN(101)
c = &color.HSL{h, s, l}
)
actual := color.Complementary(c).HSL()
assert.Equal(t, degrees.Normalize(h+180), actual.H)
assert.Equal(t, s, actual.S)
assert.Equal(t, l, actual.L)
}
}
func ExampleComplementary() {
blue := color.Must(color.ParseHex("#0000ff"))
// Yellow is the complementary color for blue.
yellow := color.Complementary(blue)
fmt.Println(yellow.Hex()) // Output: #ffff00
}
func TestSplitComplementary(t *testing.T) {
for range 1000 {
var (
h = rand.IntN(360)
s = rand.IntN(101)
l = rand.IntN(101)
c = &color.HSL{h, s, l}
)
var (
c1, c2 = color.SplitComplementary(c)
a = c1.HSL()
b = c2.HSL()
)
assert.Equal(t, degrees.Normalize(h+150), a.H)
assert.Equal(t, s, a.S)
assert.Equal(t, l, a.L)
assert.Equal(t, degrees.Normalize(h+210), b.H)
assert.Equal(t, s, b.S)
assert.Equal(t, l, b.L)
}
}
func ExampleSplitComplementary() {
cyan := color.Must(color.ParseHex("#00ffff"))
// Crimson and orange are split complementary colors of cyan.
crimson, orange := color.SplitComplementary(cyan)
fmt.Println(crimson.Hex())
fmt.Println(orange.Hex())
// Output:
// #ff0080
// #ff8000
}
func TestTriadic(t *testing.T) {
for range 1000 {
var (
h = rand.IntN(360)
s = rand.IntN(101)
l = rand.IntN(101)
c = &color.HSL{h, s, l}
)
var (
c1, c2 = color.Triadic(c)
a = c1.HSL()
b = c2.HSL()
)
assert.Equal(t, degrees.Normalize(h+120), a.H)
assert.Equal(t, s, a.S)
assert.Equal(t, l, a.L)
assert.Equal(t, degrees.Normalize(h+240), b.H)
assert.Equal(t, s, b.S)
assert.Equal(t, l, b.L)
}
}
func ExampleTriadic() {
red := color.Must(color.ParseHex("#ff0000"))
// Green and blue are the colors in the triadic colorscheme with red.
green, blue := color.Triadic(red)
fmt.Println(green.Hex())
fmt.Println(blue.Hex())
// Output:
// #00ff00
// #0000ff
}
func TestTetradic(t *testing.T) {
for range 1000 {
var (
h = rand.IntN(360)
s = rand.IntN(101)
l = rand.IntN(101)
c = &color.HSL{h, s, l}
)
var (
c1, c2, c3 = color.Tetradic(c)
a = c1.HSL()
b = c2.HSL()
d = c3.HSL()
)
assert.Equal(t, degrees.Normalize(h+90), a.H)
assert.Equal(t, s, a.S)
assert.Equal(t, l, a.L)
assert.Equal(t, degrees.Normalize(h+180), b.H)
assert.Equal(t, s, b.S)
assert.Equal(t, l, b.L)
assert.Equal(t, degrees.Normalize(h+270), d.H)
assert.Equal(t, s, d.S)
assert.Equal(t, l, d.L)
}
}
func ExampleTetradic() {
magenta := color.Must(color.ParseHex("ff00ff"))
// Orange, green and blue are the colors in the tetradic colorscheme with magenta.
orange, green, blue := color.Tetradic(magenta)
fmt.Println(orange.Hex())
fmt.Println(green.Hex())
fmt.Println(blue.Hex())
// Output:
// #ff8000
// #00ff00
// #007fff
}
func TestAnalogous(t *testing.T) {
for range 1000 {
var (
h = rand.IntN(360)
s = rand.IntN(101)
l = rand.IntN(101)
c = &color.HSL{h, s, l}
)
var (
c1, c2 = color.Analogous(c)
a = c1.HSL()
b = c2.HSL()
)
assert.Equal(t, degrees.Normalize(h-30), a.H)
assert.Equal(t, s, a.S)
assert.Equal(t, l, a.L)
assert.Equal(t, degrees.Normalize(h+30), b.H)
assert.Equal(t, s, b.S)
assert.Equal(t, l, b.L)
}
}
func ExampleAnalogous() {
orange := color.Must(color.ParseHex("#ff8000"))
// Red and yellow are adjacent to orange.
red, yellow := color.Analogous(orange)
fmt.Println(red.Hex())
fmt.Println(yellow.Hex())
// Output:
// #ff0000
// #ffff00
}