-
Notifications
You must be signed in to change notification settings - Fork 5
/
palettor_test.go
29 lines (24 loc) · 714 Bytes
/
palettor_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
package palettor
import (
"bytes"
"encoding/base64"
"image/png"
"testing"
)
// base64-encoded 4x4 png, w/ black, white, red, & blue pixels
var testImageData = []byte("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAE0lEQVQIHWMAgv///zP8ZwCC/wAh7AT8vKm73AAAAABJRU5ErkJggg==")
func TestExtract(t *testing.T) {
decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewReader(testImageData))
img, err := png.Decode(decoder)
if err != nil {
t.Fatalf("invalid test image: %s", err)
}
_, err = Extract(5, 100, img)
if err == nil {
t.Errorf("k too large, expected an error")
}
palette, _ := Extract(4, 100, img)
if palette.Count() != 4 {
t.Errorf("expected 4 colors, got %d", palette.Count())
}
}