Skip to content

Commit 32526fc

Browse files
committed
test: add palette unit tests
1 parent d295cc1 commit 32526fc

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

palette_test.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ package pi_test
55

66
import (
77
_ "embed"
8-
"github.com/elgopher/pi"
8+
"testing"
9+
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
11-
"testing"
12+
13+
"github.com/elgopher/pi"
1214
)
1315

1416
var (
@@ -71,3 +73,48 @@ func TestDecodePaletteOrErr(t *testing.T) {
7173
}
7274
})
7375
}
76+
77+
func TestFromRGB(t *testing.T) {
78+
// when
79+
rgb := pi.FromRGB(1, 128, 255)
80+
// then
81+
r, g, b := rgb.RGB()
82+
assert.Equal(t, uint8(1), r)
83+
assert.Equal(t, uint8(128), g)
84+
assert.Equal(t, uint8(255), b)
85+
}
86+
87+
func TestFromRGBf(t *testing.T) {
88+
// when
89+
rgb := pi.FromRGBf(0.004, 0.5, 1.0)
90+
// then
91+
rf, gf, bf := rgb.RGBf()
92+
assert.InDelta(t, 0.004, rf, 0.01)
93+
assert.InDelta(t, 0.5, gf, 0.01)
94+
assert.InDelta(t, 1.0, bf, 0.01)
95+
}
96+
97+
func TestRGB_String(t *testing.T) {
98+
rgb := pi.RGB(0x304050)
99+
assert.Equal(t, "0x304050", rgb.String())
100+
}
101+
102+
func TestPaletteArray_String(t *testing.T) {
103+
var p pi.PaletteArray
104+
p[0] = pi.RGB(0x010101)
105+
p[1] = pi.RGB(0x020202)
106+
p[63] = pi.RGB(0x636363)
107+
// when
108+
actual := p.String()
109+
// then
110+
assert.Equal(t,
111+
"{0:0x010101, 1:0x020202, 2:0x000000, 3:0x000000, 4:0x000000, 5:0x000000, 6:0x000000, 7:0x000000, 8:0x000000, "+
112+
"9:0x000000, 10:0x000000, 11:0x000000, 12:0x000000, 13:0x000000, 14:0x000000, 15:0x000000, 16:0x000000, "+
113+
"17:0x000000, 18:0x000000, 19:0x000000, 20:0x000000, 21:0x000000, 22:0x000000, 23:0x000000, 24:0x000000, "+
114+
"25:0x000000, 26:0x000000, 27:0x000000, 28:0x000000, 29:0x000000, 30:0x000000, 31:0x000000, 32:0x000000, "+
115+
"33:0x000000, 34:0x000000, 35:0x000000, 36:0x000000, 37:0x000000, 38:0x000000, 39:0x000000, 40:0x000000, "+
116+
"41:0x000000, 42:0x000000, 43:0x000000, 44:0x000000, 45:0x000000, 46:0x000000, 47:0x000000, 48:0x000000, "+
117+
"49:0x000000, 50:0x000000, 51:0x000000, 52:0x000000, 53:0x000000, 54:0x000000, 55:0x000000, 56:0x000000, "+
118+
"57:0x000000, 58:0x000000, 59:0x000000, 60:0x000000, 61:0x000000, 62:0x000000, 63:0x636363, }",
119+
actual)
120+
}

0 commit comments

Comments
 (0)