color/nlgraya/nlgraya_test.go

54 lines
1.2 KiB
Go

package nlgraya
import (
"math"
"testing"
"smariot.com/color/internal/helper"
)
func eq(c0, c1 Color) bool {
return helper.EqFloat64SliceFuzzy(
[]float64{c0.Y, c0.A},
[]float64{c1.Y, c1.A},
)
}
func midpoint(c0, c1 Color) Color {
return Color{(c0.Y + c1.Y) / 2, (c0.A + c1.A) / 2}
}
func TestModel(t *testing.T) {
helper.TestModel(t, false, true, Model, eq, []helper.ConvertTest[Color]{
// These is a very illegal colour. If it makes it through
// unchanged, we can be reasonably confident no colour space conversions were
// attempted.
{
Name: "passthrough +inf",
In: Color{math.Inf(1), 0},
Out: Color{math.Inf(1), 0},
}, {
Name: "passthrough +inf",
In: Color{math.Inf(-1), math.NaN()},
Out: Color{math.Inf(-1), math.NaN()},
}, {
Name: "passthrough nan",
In: Color{math.NaN(), math.Inf(1)},
Out: Color{math.NaN(), math.Inf(1)},
},
})
}
func distance(a, b Color) float64 {
d := Distance(a, b)
dSqr := DistanceSqr(a, b)
if !helper.EqFloat64Fuzzy(d*d, dSqr) {
panic("Distance and DistanceSqr are not equivalent")
}
return d
}
func TestDistance(t *testing.T) {
helper.TestDistance(t, false, true, midpoint, distance, Model)
}