1
1
mirror of https://github.com/walles/moar.git synced 2024-09-11 20:17:13 +03:00
moar/twin/colors_test.go
Johan Walles f6571b3942 Improve color downsampling
Tested on the green-gradient.txt sample file, looks much better after
this change.
2024-01-12 15:01:37 +01:00

59 lines
1.1 KiB
Go

package twin
import (
"testing"
"gotest.tools/v3/assert"
)
func TestDownsample24BitsTo16Colors(t *testing.T) {
assert.Equal(t,
NewColor24Bit(255, 255, 255).downsampleTo(ColorType16),
NewColor16(15),
)
}
func TestDownsample24BitsTo256Colors(t *testing.T) {
assert.Equal(t,
NewColor24Bit(255, 255, 255).downsampleTo(ColorType256),
// From https://jonasjacek.github.io/colors/
NewColor256(231),
)
}
func TestRealWorldDownsampling(t *testing.T) {
assert.Equal(t,
NewColor24Bit(0xd0, 0xd0, 0xd0).downsampleTo(ColorType256),
NewColor256(252), // From https://jonasjacek.github.io/colors/
)
}
func TestAnsiStringWithDownSampling(t *testing.T) {
assert.Equal(t,
NewColor24Bit(0xd0, 0xd0, 0xd0).ansiString(true, ColorType256),
"\x1b[38;5;252m",
)
}
func TestAnsiStringDefault(t *testing.T) {
assert.Equal(t,
ColorDefault.ansiString(true, ColorType16),
"\x1b[39m",
)
}
func TestDistance(t *testing.T) {
// Black -> white
assert.Equal(t,
NewColor24Bit(0, 0, 0).Distance(NewColor24Bit(255, 255, 255)),
1.0,
)
// White -> black
assert.Equal(t,
NewColor24Bit(255, 255, 255).Distance(NewColor24Bit(0, 0, 0)),
1.0,
)
}