82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package color_test
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"git.akyoto.dev/go/assert"
|
|
"git.akyoto.dev/go/color"
|
|
)
|
|
|
|
func TestNoColors(t *testing.T) {
|
|
color.Terminal = false
|
|
testRGBColors(t)
|
|
testLCHColors(t)
|
|
}
|
|
|
|
func TestColors(t *testing.T) {
|
|
color.Terminal = true
|
|
testRGBColors(t)
|
|
testLCHColors(t)
|
|
}
|
|
|
|
func TestRainbow(t *testing.T) {
|
|
color.Terminal = true
|
|
|
|
for chroma := range 5 {
|
|
for lightness := range 21 {
|
|
for hue := range 80 {
|
|
c := color.LCH(color.Value(lightness)*0.05, color.Value(chroma)*0.05, color.Value(hue)*4.5)
|
|
c.Print("█")
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|
|
}
|
|
|
|
func testRGBColors(t *testing.T) {
|
|
rgbColors := map[string]color.Color{
|
|
"RGB.black": color.RGB(0.0, 0.0, 0.0),
|
|
"RGB.white": color.RGB(1.0, 1.0, 1.0),
|
|
"RGB.red": color.RGB(1.0, 0.0, 0.0),
|
|
"RGB.green": color.RGB(0.0, 1.0, 0.0),
|
|
"RGB.blue": color.RGB(0.0, 0.0, 1.0),
|
|
}
|
|
|
|
for name, c := range rgbColors {
|
|
testColor(t, c, name)
|
|
}
|
|
}
|
|
|
|
func testLCHColors(t *testing.T) {
|
|
lchColors := map[string]color.Color{
|
|
"LCH.black": color.LCH(0.0, 0.0, 0.0),
|
|
"LCH.white": color.LCH(1.0, 0.0, 0.0),
|
|
"LCH.red": color.LCH(0.6, 0.5, 20.0),
|
|
"LCH.green": color.LCH(0.6, 0.5, 161.0),
|
|
"LCH.blue": color.LCH(0.6, 0.5, 240.0),
|
|
}
|
|
|
|
for name, c := range lchColors {
|
|
testColor(t, c, name)
|
|
}
|
|
}
|
|
|
|
func testColor(t *testing.T, c color.Color, name string) {
|
|
assert.True(t, c.R >= 0.0)
|
|
assert.True(t, c.G >= 0.0)
|
|
assert.True(t, c.B >= 0.0)
|
|
|
|
assert.True(t, c.R <= 1.0)
|
|
assert.True(t, c.G <= 1.0)
|
|
assert.True(t, c.B <= 1.0)
|
|
|
|
c.Fprint(io.Discard, name)
|
|
c.Print(name)
|
|
c.Println(name)
|
|
}
|