1
1
mirror of https://github.com/walles/moar.git synced 2024-11-26 13:46:16 +03:00
moar/twin/palette256_test.go
Johan Walles d511e50652 Downsample colors to terminal palette
As neeed.

This enables you to view 24 bit color documents in a 256 color terminal.
With reduced quality obviously, but still.
2023-12-19 08:47:40 +01:00

48 lines
1.1 KiB
Go

package twin
import (
"testing"
"gotest.tools/v3/assert"
)
func TestColorRgbFirst16(t *testing.T) {
r, g, b := color256ToRGB(5)
assert.Equal(t, r, float64(0x80)/255.0)
assert.Equal(t, g, float64(0x00)/255.0)
assert.Equal(t, b, float64(0x80)/255.0)
}
func TestColorToRgbInTheGrey(t *testing.T) {
r, g, b := color256ToRGB(252)
assert.Equal(t, r, float64(0xd0)/255.0)
assert.Equal(t, g, float64(0xd0)/255.0)
assert.Equal(t, b, float64(0xd0)/255.0)
}
func TestColorToRgbInThe6x6Cube(t *testing.T) {
r, g, b := color256ToRGB(101)
assert.Equal(t, r, float64(0x87)/255.0)
assert.Equal(t, g, float64(0x87)/255.0)
assert.Equal(t, b, float64(0x5f)/255.0)
}
func TestColorToRgbStart6x6Cube(t *testing.T) {
r, g, b := color256ToRGB(16)
assert.Equal(t, r, float64(0x00)/255.0)
assert.Equal(t, g, float64(0x00)/255.0)
assert.Equal(t, b, float64(0x00)/255.0)
}
func TestColorRgbEnd6x6Cube(t *testing.T) {
r, g, b := color256ToRGB(231)
assert.Equal(t, r, float64(0xff)/255.0)
assert.Equal(t, g, float64(0xff)/255.0)
assert.Equal(t, b, float64(0xff)/255.0)
}