@@ -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 := takecolor (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 := takecolor (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 := takecolor (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 := takecolor (img , 2 )
267+ result := takeThemeColorsKMeans (img , 2 )
268268 if len (result ) == 2 && colorInSlice (Red , result , 5 ) && colorInSlice (Blue , result , 5 ) {
269269 return // 成功分离,测试通过
270270 }
@@ -276,8 +276,8 @@ func TestTakecolor_Deterministic_SolidImage(t *testing.T) {
276276 // 纯色图像下,无论随机种子如何,结果应完全一致
277277 c := color.RGBA {77 , 88 , 99 , 255 }
278278 img := solidImage (10 , 10 , c )
279- r1 := takecolor (img , 2 )
280- r2 := takecolor (img , 2 )
279+ r1 := takeThemeColorsKMeans (img , 2 )
280+ r2 := takeThemeColorsKMeans (img , 2 )
281281 if ! clustersEqual (r1 , r2 ) {
282282 t .Errorf ("takecolor on solid image should be deterministic: r1=%v, r2=%v" , r1 , r2 )
283283 }
@@ -296,7 +296,7 @@ func TestTakecolor_AllClustersHaveValidRGB(t *testing.T) {
296296 })
297297 }
298298 }
299- result := takecolor (img , 4 )
299+ result := takeThemeColorsKMeans (img , 4 )
300300 if len (result ) != 4 {
301301 t .Fatalf ("expected 4 clusters, got %d" , len (result ))
302302 }
@@ -352,7 +352,7 @@ func BenchmarkTakecolor_16x16_K3(b *testing.B) {
352352 }
353353 b .ResetTimer ()
354354 for range b .N {
355- takecolor (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- takecolor (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- takecolor (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- takecolor (img , 5 )
391+ takeThemeColorsKMeans (img , 5 )
392392 }
393393}
0 commit comments