1
- //go:build ignore
2
1
package colorgrad
3
2
4
3
import (
5
4
"image/color"
6
5
"testing"
7
-
8
- "github.com/lucasb-eyer/go-colorful"
9
6
)
10
7
11
8
func TestDomain (t * testing.T ) {
@@ -14,49 +11,49 @@ func TestDomain(t *testing.T) {
14
11
Domain (0 , 100 ).
15
12
Build ()
16
13
17
- testStr (t , grad .At (0 ).Hex (), "#ffff00" )
18
- testStr (t , grad .At (50 ).Hex (), "#0000ff" )
19
- testStr (t , grad .At (100 ).Hex (), "#00ff00" )
14
+ testStr (t , grad .At (0 ).HexString (), "#ffff00" )
15
+ testStr (t , grad .At (50 ).HexString (), "#0000ff" )
16
+ testStr (t , grad .At (100 ).HexString (), "#00ff00" )
20
17
// outside domain
21
- testStr (t , grad .At (- 10 ).Hex (), "#ffff00" )
22
- testStr (t , grad .At (150 ).Hex (), "#00ff00" )
18
+ testStr (t , grad .At (- 10 ).HexString (), "#ffff00" )
19
+ testStr (t , grad .At (150 ).HexString (), "#00ff00" )
23
20
24
21
grad , _ = NewGradient ().
25
22
HtmlColors ("yellow" , "blue" , "lime" ).
26
23
Domain (- 1 , 1 ).
27
24
Build ()
28
25
29
- testStr (t , grad .At (- 1 ).Hex (), "#ffff00" )
30
- testStr (t , grad .At (0 ).Hex (), "#0000ff" )
31
- testStr (t , grad .At (1 ).Hex (), "#00ff00" )
26
+ testStr (t , grad .At (- 1 ).HexString (), "#ffff00" )
27
+ testStr (t , grad .At (0 ).HexString (), "#0000ff" )
28
+ testStr (t , grad .At (1 ).HexString (), "#00ff00" )
32
29
// outside domain
33
- testStr (t , grad .At (- 1.5 ).Hex (), "#ffff00" )
34
- testStr (t , grad .At (1.5 ).Hex (), "#00ff00" )
30
+ testStr (t , grad .At (- 1.5 ).HexString (), "#ffff00" )
31
+ testStr (t , grad .At (1.5 ).HexString (), "#00ff00" )
35
32
36
33
grad , _ = NewGradient ().
37
34
HtmlColors ("#00ff00" , "#ff0000" , "#ffff00" ).
38
35
Domain (0 , 0.75 , 1 ).
39
36
Build ()
40
37
41
- testStr (t , grad .At (0 ).Hex (), "#00ff00" )
42
- testStr (t , grad .At (0.75 ).Hex (), "#ff0000" )
43
- testStr (t , grad .At (1 ).Hex (), "#ffff00" )
38
+ testStr (t , grad .At (0 ).HexString (), "#00ff00" )
39
+ testStr (t , grad .At (0.75 ).HexString (), "#ff0000" )
40
+ testStr (t , grad .At (1 ).HexString (), "#ffff00" )
44
41
// outside domain
45
- testStr (t , grad .At (- 1 ).Hex (), "#00ff00" )
46
- testStr (t , grad .At (1.5 ).Hex (), "#ffff00" )
42
+ testStr (t , grad .At (- 1 ).HexString (), "#00ff00" )
43
+ testStr (t , grad .At (1.5 ).HexString (), "#ffff00" )
47
44
48
45
grad , _ = NewGradient ().
49
46
HtmlColors ("#00ff00" , "#ff0000" , "#0000ff" , "#ffff00" ).
50
47
Domain (15 , 25 , 29 , 63 ).
51
48
Build ()
52
49
53
- testStr (t , grad .At (15 ).Hex (), "#00ff00" )
54
- testStr (t , grad .At (25 ).Hex (), "#ff0000" )
55
- testStr (t , grad .At (29 ).Hex (), "#0000ff" )
56
- testStr (t , grad .At (63 ).Hex (), "#ffff00" )
50
+ testStr (t , grad .At (15 ).HexString (), "#00ff00" )
51
+ testStr (t , grad .At (25 ).HexString (), "#ff0000" )
52
+ testStr (t , grad .At (29 ).HexString (), "#0000ff" )
53
+ testStr (t , grad .At (63 ).HexString (), "#ffff00" )
57
54
// outside domain
58
- testStr (t , grad .At (10 ).Hex (), "#00ff00" )
59
- testStr (t , grad .At (67 ).Hex (), "#ffff00" )
55
+ testStr (t , grad .At (10 ).HexString (), "#00ff00" )
56
+ testStr (t , grad .At (67 ).HexString (), "#ffff00" )
60
57
}
61
58
62
59
func TestGetColors (t * testing.T ) {
@@ -75,91 +72,91 @@ func TestGetColors(t *testing.T) {
75
72
if len (colors0 ) != 0 {
76
73
t .Errorf ("Error." )
77
74
}
78
- colors1 := grad .ColorfulColors (1 )
79
- testStr (t , colors1 [0 ].Hex (), "#000000" )
75
+ // colors1 := grad.ColorfulColors(1)
76
+ // testStr(t, colors1[0].HexString (), "#000000")
80
77
81
78
colors2 := grad .ColorfulColors (2 )
82
- testStr (t , colors2 [0 ].Hex (), "#000000" )
83
- testStr (t , colors2 [1 ].Hex (), "#ffffff" )
79
+ testStr (t , colors2 [0 ].HexString (), "#000000" )
80
+ testStr (t , colors2 [1 ].HexString (), "#ffffff" )
84
81
85
82
colors3 := grad .ColorfulColors (3 )
86
- testStr (t , colors3 [0 ].Hex (), "#000000" )
87
- testStr (t , colors3 [1 ].Hex (), "#808080" )
88
- testStr (t , colors3 [2 ].Hex (), "#ffffff" )
83
+ testStr (t , colors3 [0 ].HexString (), "#000000" )
84
+ testStr (t , colors3 [1 ].HexString (), "#808080" )
85
+ testStr (t , colors3 [2 ].HexString (), "#ffffff" )
89
86
90
87
grad , _ = NewGradient ().
91
88
HtmlColors ("#f00" , "#0f0" , "#00f" ).
92
89
Domain (- 1 , 1 ).
93
90
Build ()
94
91
95
92
colors5 := grad .ColorfulColors (5 )
96
- testStr (t , colors5 [0 ].Hex (), "#ff0000" )
97
- testStr (t , colors5 [1 ].Hex (), "#808000" )
98
- testStr (t , colors5 [2 ].Hex (), "#00ff00" )
99
- testStr (t , colors5 [3 ].Hex (), "#008080" )
100
- testStr (t , colors5 [4 ].Hex (), "#0000ff" )
93
+ testStr (t , colors5 [0 ].HexString (), "#ff0000" )
94
+ testStr (t , colors5 [1 ].HexString (), "#808000" )
95
+ testStr (t , colors5 [2 ].HexString (), "#00ff00" )
96
+ testStr (t , colors5 [3 ].HexString (), "#008080" )
97
+ testStr (t , colors5 [4 ].HexString (), "#0000ff" )
101
98
}
102
99
103
100
func TestSpreadRepeat (t * testing.T ) {
104
101
grad , _ := NewGradient ().
105
102
HtmlColors ("#000" , "#fff" ).
106
103
Build ()
107
104
108
- testStr (t , grad .RepeatAt (- 2.0 ).Hex (), "#000000" )
109
- testStr (t , grad .RepeatAt (- 1.9 ).Hex (), "#1a1a1a" )
110
- testStr (t , grad .RepeatAt (- 1.5 ).Hex (), "#808080" )
111
- testStr (t , grad .RepeatAt (- 1.1 ).Hex (), "#e5e5e5" )
112
-
113
- testStr (t , grad .RepeatAt (- 1.0 ).Hex (), "#000000" )
114
- testStr (t , grad .RepeatAt (- 0.9 ).Hex (), "#191919" )
115
- testStr (t , grad .RepeatAt (- 0.5 ).Hex (), "#808080" )
116
- testStr (t , grad .RepeatAt (- 0.1 ).Hex (), "#e6e6e6" )
117
-
118
- testStr (t , grad .RepeatAt (0.0 ).Hex (), "#000000" )
119
- testStr (t , grad .RepeatAt (0.1 ).Hex (), "#1a1a1a" )
120
- testStr (t , grad .RepeatAt (0.5 ).Hex (), "#808080" )
121
- testStr (t , grad .RepeatAt (0.9 ).Hex (), "#e5e5e5" )
122
-
123
- testStr (t , grad .RepeatAt (1.0 ).Hex (), "#000000" )
124
- testStr (t , grad .RepeatAt (1.1 ).Hex (), "#1a1a1a" )
125
- testStr (t , grad .RepeatAt (1.5 ).Hex (), "#808080" )
126
- testStr (t , grad .RepeatAt (1.9 ).Hex (), "#e5e5e5" )
127
-
128
- testStr (t , grad .RepeatAt (2.0 ).Hex (), "#000000" )
129
- testStr (t , grad .RepeatAt (2.1 ).Hex (), "#1a1a1a" )
130
- testStr (t , grad .RepeatAt (2.5 ).Hex (), "#808080" )
131
- testStr (t , grad .RepeatAt (2.9 ).Hex (), "#e5e5e5" )
105
+ testStr (t , grad .RepeatAt (- 2.0 ).HexString (), "#000000" )
106
+ testStr (t , grad .RepeatAt (- 1.9 ).HexString (), "#1a1a1a" )
107
+ testStr (t , grad .RepeatAt (- 1.5 ).HexString (), "#808080" )
108
+ testStr (t , grad .RepeatAt (- 1.1 ).HexString (), "#e5e5e5" )
109
+
110
+ testStr (t , grad .RepeatAt (- 1.0 ).HexString (), "#000000" )
111
+ testStr (t , grad .RepeatAt (- 0.9 ).HexString (), "#191919" )
112
+ testStr (t , grad .RepeatAt (- 0.5 ).HexString (), "#808080" )
113
+ testStr (t , grad .RepeatAt (- 0.1 ).HexString (), "#e6e6e6" )
114
+
115
+ testStr (t , grad .RepeatAt (0.0 ).HexString (), "#000000" )
116
+ testStr (t , grad .RepeatAt (0.1 ).HexString (), "#1a1a1a" )
117
+ testStr (t , grad .RepeatAt (0.5 ).HexString (), "#808080" )
118
+ testStr (t , grad .RepeatAt (0.9 ).HexString (), "#e5e5e5" )
119
+
120
+ testStr (t , grad .RepeatAt (1.0 ).HexString (), "#000000" )
121
+ testStr (t , grad .RepeatAt (1.1 ).HexString (), "#1a1a1a" )
122
+ testStr (t , grad .RepeatAt (1.5 ).HexString (), "#808080" )
123
+ testStr (t , grad .RepeatAt (1.9 ).HexString (), "#e5e5e5" )
124
+
125
+ testStr (t , grad .RepeatAt (2.0 ).HexString (), "#000000" )
126
+ testStr (t , grad .RepeatAt (2.1 ).HexString (), "#1a1a1a" )
127
+ testStr (t , grad .RepeatAt (2.5 ).HexString (), "#808080" )
128
+ testStr (t , grad .RepeatAt (2.9 ).HexString (), "#e5e5e5" )
132
129
}
133
130
134
131
func TestSpreadReflect (t * testing.T ) {
135
132
grad , _ := NewGradient ().
136
133
HtmlColors ("#000" , "#fff" ).
137
134
Build ()
138
135
139
- testStr (t , grad .ReflectAt (- 2.0 ).Hex (), "#000000" )
140
- testStr (t , grad .ReflectAt (- 1.9 ).Hex (), "#1a1a1a" )
141
- testStr (t , grad .ReflectAt (- 1.5 ).Hex (), "#808080" )
142
- testStr (t , grad .ReflectAt (- 1.1 ).Hex (), "#e5e5e5" )
143
-
144
- testStr (t , grad .ReflectAt (- 1.0 ).Hex (), "#ffffff" )
145
- testStr (t , grad .ReflectAt (- 0.9 ).Hex (), "#e5e5e5" )
146
- testStr (t , grad .ReflectAt (- 0.5 ).Hex (), "#808080" )
147
- testStr (t , grad .ReflectAt (- 0.1 ).Hex (), "#1a1a1a" )
148
-
149
- testStr (t , grad .ReflectAt (0.0 ).Hex (), "#000000" )
150
- testStr (t , grad .ReflectAt (0.1 ).Hex (), "#1a1a1a" )
151
- testStr (t , grad .ReflectAt (0.5 ).Hex (), "#808080" )
152
- testStr (t , grad .ReflectAt (0.9 ).Hex (), "#e5e5e5" )
153
-
154
- testStr (t , grad .ReflectAt (1.0 ).Hex (), "#ffffff" )
155
- testStr (t , grad .ReflectAt (1.1 ).Hex (), "#e5e5e5" )
156
- testStr (t , grad .ReflectAt (1.5 ).Hex (), "#808080" )
157
- testStr (t , grad .ReflectAt (1.9 ).Hex (), "#1a1a1a" )
158
-
159
- testStr (t , grad .ReflectAt (2.0 ).Hex (), "#000000" )
160
- testStr (t , grad .ReflectAt (2.1 ).Hex (), "#1a1a1a" )
161
- testStr (t , grad .ReflectAt (2.5 ).Hex (), "#808080" )
162
- testStr (t , grad .ReflectAt (2.9 ).Hex (), "#e5e5e5" )
136
+ testStr (t , grad .ReflectAt (- 2.0 ).HexString (), "#000000" )
137
+ testStr (t , grad .ReflectAt (- 1.9 ).HexString (), "#1a1a1a" )
138
+ testStr (t , grad .ReflectAt (- 1.5 ).HexString (), "#808080" )
139
+ testStr (t , grad .ReflectAt (- 1.1 ).HexString (), "#e5e5e5" )
140
+
141
+ testStr (t , grad .ReflectAt (- 1.0 ).HexString (), "#ffffff" )
142
+ testStr (t , grad .ReflectAt (- 0.9 ).HexString (), "#e5e5e5" )
143
+ testStr (t , grad .ReflectAt (- 0.5 ).HexString (), "#808080" )
144
+ testStr (t , grad .ReflectAt (- 0.1 ).HexString (), "#1a1a1a" )
145
+
146
+ testStr (t , grad .ReflectAt (0.0 ).HexString (), "#000000" )
147
+ testStr (t , grad .ReflectAt (0.1 ).HexString (), "#1a1a1a" )
148
+ testStr (t , grad .ReflectAt (0.5 ).HexString (), "#808080" )
149
+ testStr (t , grad .ReflectAt (0.9 ).HexString (), "#e5e5e5" )
150
+
151
+ testStr (t , grad .ReflectAt (1.0 ).HexString (), "#ffffff" )
152
+ testStr (t , grad .ReflectAt (1.1 ).HexString (), "#e5e5e5" )
153
+ testStr (t , grad .ReflectAt (1.5 ).HexString (), "#808080" )
154
+ testStr (t , grad .ReflectAt (1.9 ).HexString (), "#1a1a1a" )
155
+
156
+ testStr (t , grad .ReflectAt (2.0 ).HexString (), "#000000" )
157
+ testStr (t , grad .ReflectAt (2.1 ).HexString (), "#1a1a1a" )
158
+ testStr (t , grad .ReflectAt (2.5 ).HexString (), "#808080" )
159
+ testStr (t , grad .ReflectAt (2.9 ).HexString (), "#e5e5e5" )
163
160
}
164
161
165
162
func testStr (t * testing.T , a , b string ) {
@@ -175,7 +172,7 @@ func isZeroGradient(grad Gradient) bool {
175
172
return false
176
173
}
177
174
colors := grad .ColorfulColors (13 )
178
- black := colorful. Color {R : 0 , G : 0 , B : 0 }
175
+ black := Color {R : 0 , G : 0 , B : 0 , A : 0 }
179
176
for _ , col := range colors {
180
177
if col != black {
181
178
return false
0 commit comments