@@ -160,44 +160,44 @@ func TestDistance_IgnoresAlpha(t *testing.T) {
160160func TestClustersEqual_Equal (t * testing.T ) {
161161 a := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }, {0 , 0 , 255 , 255 }}
162162 b := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }, {0 , 0 , 255 , 255 }}
163- if ! clustersEqual (a , b ) {
163+ if ! isArrayRGBAEqual (a , b ) {
164164 t .Error ("clustersEqual should return true for identical slices" )
165165 }
166166}
167167
168168func TestClustersEqual_NotEqual (t * testing.T ) {
169169 a := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }}
170170 b := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 0 , 255 , 255 }}
171- if clustersEqual (a , b ) {
171+ if isArrayRGBAEqual (a , b ) {
172172 t .Error ("clustersEqual should return false for different slices" )
173173 }
174174}
175175
176176func TestClustersEqual_DifferentLength (t * testing.T ) {
177177 a := []color.RGBA {{255 , 0 , 0 , 255 }}
178178 b := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }}
179- if clustersEqual (a , b ) {
179+ if isArrayRGBAEqual (a , b ) {
180180 t .Error ("clustersEqual should return false for slices of different lengths" )
181181 }
182182}
183183
184184func TestClustersEqual_Empty (t * testing.T ) {
185- if ! clustersEqual ([]color.RGBA {}, []color.RGBA {}) {
185+ if ! isArrayRGBAEqual ([]color.RGBA {}, []color.RGBA {}) {
186186 t .Error ("clustersEqual should return true for two empty slices" )
187187 }
188188}
189189
190190func TestClustersEqual_OneEmpty (t * testing.T ) {
191191 a := []color.RGBA {{255 , 0 , 0 , 255 }}
192- if clustersEqual (a , []color.RGBA {}) {
192+ if isArrayRGBAEqual (a , []color.RGBA {}) {
193193 t .Error ("clustersEqual should return false when one slice is empty" )
194194 }
195195}
196196
197197func TestClustersEqual_SingleElement (t * testing.T ) {
198198 a := []color.RGBA {{100 , 100 , 100 , 255 }}
199199 b := []color.RGBA {{100 , 100 , 100 , 255 }}
200- if ! clustersEqual (a , b ) {
200+ if ! isArrayRGBAEqual (a , b ) {
201201 t .Error ("clustersEqual should return true for identical single-element slices" )
202202 }
203203}
@@ -206,7 +206,7 @@ func TestClustersEqual_DiffersOnlyInAlpha(t *testing.T) {
206206 a := []color.RGBA {{100 , 100 , 100 , 255 }}
207207 b := []color.RGBA {{100 , 100 , 100 , 0 }}
208208 // RGBA 结构体逐字段比较,Alpha 也参与比较
209- if clustersEqual (a , b ) {
209+ if isArrayRGBAEqual (a , b ) {
210210 t .Error ("clustersEqual should return false when alpha differs" )
211211 }
212212}
@@ -216,7 +216,7 @@ func TestClustersEqual_DiffersOnlyInAlpha(t *testing.T) {
216216func TestTakecolor_ReturnsKColors (t * testing.T ) {
217217 img := solidImage (10 , 10 , color.RGBA {128 , 64 , 32 , 255 })
218218 for k := 1 ; k <= 5 ; k ++ {
219- result := takeThemeColorsKMeans (img , k )
219+ result := TakeThemeColorsKMeans (img , k )
220220 if len (result ) != k {
221221 t .Errorf ("takecolor with k=%d returned %d colors, want %d" , k , len (result ), k )
222222 }
@@ -226,7 +226,7 @@ func TestTakecolor_ReturnsKColors(t *testing.T) {
226226func TestTakecolor_SolidColorK1 (t * testing.T ) {
227227 c := color.RGBA {200 , 100 , 50 , 255 }
228228 img := solidImage (20 , 20 , c )
229- result := takeThemeColorsKMeans (img , 1 )
229+ result := TakeThemeColorsKMeans (img , 1 )
230230 if len (result ) != 1 {
231231 t .Fatalf ("expected 1 color, got %d" , len (result ))
232232 }
@@ -242,7 +242,7 @@ func TestTakecolor_SolidColorKGreaterThan1(t *testing.T) {
242242 // 故只验证:返回 k 个颜色,且其中至少一个与原始颜色完全匹配。
243243 c := color.RGBA {10 , 200 , 150 , 255 }
244244 img := solidImage (15 , 15 , c )
245- result := takeThemeColorsKMeans (img , 3 )
245+ result := TakeThemeColorsKMeans (img , 3 )
246246 if len (result ) != 3 {
247247 t .Fatalf ("expected 3 colors, got %d" , len (result ))
248248 }
@@ -264,7 +264,7 @@ func TestTakecolor_TwoDistinctColors(t *testing.T) {
264264 img := twoColorImage (20 , 20 , Red , Blue )
265265 const maxAttempts = 30
266266 for range maxAttempts {
267- result := takeThemeColorsKMeans (img , 2 )
267+ result := TakeThemeColorsKMeans (img , 2 )
268268 if len (result ) == 2 && colorInSlice (Red , result , 5 ) && colorInSlice (Blue , result , 5 ) {
269269 return // 成功分离,测试通过
270270 }
@@ -276,9 +276,9 @@ func TestTakecolor_Deterministic_SolidImage(t *testing.T) {
276276 // 纯色图像下,无论随机种子如何,结果应完全一致
277277 c := color.RGBA {77 , 88 , 99 , 255 }
278278 img := solidImage (10 , 10 , c )
279- r1 := takeThemeColorsKMeans (img , 2 )
280- r2 := takeThemeColorsKMeans (img , 2 )
281- if ! clustersEqual (r1 , r2 ) {
279+ r1 := TakeThemeColorsKMeans (img , 2 )
280+ r2 := TakeThemeColorsKMeans (img , 2 )
281+ if ! isArrayRGBAEqual (r1 , r2 ) {
282282 t .Errorf ("takecolor on solid image should be deterministic: r1=%v, r2=%v" , r1 , r2 )
283283 }
284284}
@@ -296,7 +296,7 @@ func TestTakecolor_AllClustersHaveValidRGB(t *testing.T) {
296296 })
297297 }
298298 }
299- result := takeThemeColorsKMeans (img , 4 )
299+ result := TakeThemeColorsKMeans (img , 4 )
300300 if len (result ) != 4 {
301301 t .Fatalf ("expected 4 clusters, got %d" , len (result ))
302302 }
@@ -329,7 +329,7 @@ func BenchmarkClustersEqual_Equal(b *testing.B) {
329329 c := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }, {0 , 0 , 255 , 255 }, {128 , 128 , 128 , 255 }}
330330 b .ResetTimer ()
331331 for range b .N {
332- clustersEqual (a , c )
332+ isArrayRGBAEqual (a , c )
333333 }
334334}
335335
@@ -338,7 +338,7 @@ func BenchmarkClustersEqual_NotEqual(b *testing.B) {
338338 c := []color.RGBA {{255 , 0 , 0 , 255 }, {0 , 255 , 0 , 255 }, {0 , 0 , 255 , 255 }, {200 , 200 , 200 , 255 }}
339339 b .ResetTimer ()
340340 for range b .N {
341- clustersEqual (a , c )
341+ isArrayRGBAEqual (a , c )
342342 }
343343}
344344
@@ -352,7 +352,7 @@ func BenchmarkTakecolor_16x16_K3(b *testing.B) {
352352 }
353353 b .ResetTimer ()
354354 for range b .N {
355- takeThemeColorsKMeans (img , 3 )
355+ TakeThemeColorsKMeans (img , 3 )
356356 }
357357}
358358
@@ -366,7 +366,7 @@ func BenchmarkTakecolor_64x64_K4(b *testing.B) {
366366 }
367367 b .ResetTimer ()
368368 for range b .N {
369- takeThemeColorsKMeans (img , 4 )
369+ TakeThemeColorsKMeans (img , 4 )
370370 }
371371}
372372
@@ -380,14 +380,14 @@ func BenchmarkTakecolor_128x128_K8(b *testing.B) {
380380 }
381381 b .ResetTimer ()
382382 for range b .N {
383- takeThemeColorsKMeans (img , 8 )
383+ TakeThemeColorsKMeans (img , 8 )
384384 }
385385}
386386
387387func BenchmarkTakecolor_SolidColor_K5 (b * testing.B ) {
388388 img := solidImage (64 , 64 , color.RGBA {200 , 100 , 50 , 255 })
389389 b .ResetTimer ()
390390 for range b .N {
391- takeThemeColorsKMeans (img , 5 )
391+ TakeThemeColorsKMeans (img , 5 )
392392 }
393393}
0 commit comments