-
Notifications
You must be signed in to change notification settings - Fork 1
/
palette_test.go
108 lines (93 loc) · 2.23 KB
/
palette_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
package ppic_test
import (
"image/color"
"testing"
"github.com/jackwilsdon/go-ppic"
)
func colorsEqual(a, b color.Color) bool {
aR, aG, aB, aA := a.RGBA()
bR, bG, bB, bA := b.RGBA()
return aR == bR && aG == bG && aB == bB && aA == bA
}
func TestPalette(t *testing.T) {
p := ppic.Palette{Foreground: color.Black, Background: color.White}
pp := p.Palette()
// Make sure that the first item is the background color.
if p.Background != pp[0] {
t.Errorf("expected pp[0] to be %#v but got %#v", p.Background, pp[0])
}
// Make sure that the second item is the foreground color.
if p.Foreground != pp[1] {
t.Errorf("expected pp[1] to be %#v but got %#v", p.Foreground, pp[1])
}
}
func TestGeneratePalette(t *testing.T) {
cases := []struct {
text string
palette ppic.Palette
}{
{
text: "",
palette: ppic.Palette{
Foreground: color.RGBA{R: 0xFC, G: 0x1C, B: 0x14, A: 0xFF},
Background: color.White,
},
},
{
text: "jackwilsdon",
palette: ppic.Palette{
Foreground: color.RGBA{R: 0xEA, G: 0xE3, B: 0xA4, A: 0xFF},
Background: color.White,
},
},
{
text: "testing, 123",
palette: ppic.Palette{
Foreground: color.RGBA{R: 0xBD, G: 0x3A, B: 0x3B, A: 0xFF},
Background: color.White,
},
},
}
for _, c := range cases {
c := c
name := c.text
if len(name) == 0 {
name = "[empty]"
}
t.Run(name, func(t *testing.T) {
p := ppic.GeneratePalette(c.text)
// Check the foreground color.
if !colorsEqual(c.palette.Foreground, p.Foreground) {
eR, eG, eB, eA := c.palette.Foreground.RGBA()
aR, aG, aB, aA := p.Foreground.RGBA()
t.Errorf(
"expected foreground to be %02X%02X%02X%02X but got %02X%02X%02X%02X",
uint8(eR),
uint8(eG),
uint8(eB),
uint8(eA),
uint8(aR),
uint8(aG),
uint8(aB),
uint8(aA),
)
}
// Check the background color.
if !colorsEqual(c.palette.Background, p.Background) {
eR, eG, eB, eA := c.palette.Background.RGBA()
aR, aG, aB, aA := p.Background.RGBA()
t.Errorf(
"expected background to be %02X%02X%02X%02X but got %02X%02X%02X%02X",
uint8(eR),
uint8(eG),
uint8(eB),
uint8(eA),
uint8(aR),
uint8(aG),
uint8(aB),
uint8(aA),
)
}
})
}
}