48 lines
922 B
Go
48 lines
922 B
Go
|
package lgray
|
||
|
|
||
|
import (
|
||
|
"math"
|
||
|
"testing"
|
||
|
|
||
|
"smariot.com/color/internal/helper"
|
||
|
)
|
||
|
|
||
|
func eq(c0, c1 Color) bool {
|
||
|
return helper.EqFloat64Fuzzy(c0.Y, c1.Y)
|
||
|
}
|
||
|
|
||
|
func midpoint(c0, c1 Color) Color {
|
||
|
return Color{(c0.Y + c1.Y) / 2}
|
||
|
}
|
||
|
|
||
|
func TestModel(t *testing.T) {
|
||
|
helper.TestModel(t, false, false, Model, eq, []helper.ConvertTest[Color]{
|
||
|
{
|
||
|
Name: "passthrough +inf",
|
||
|
In: Color{math.Inf(1)},
|
||
|
Out: Color{math.Inf(1)},
|
||
|
}, {
|
||
|
Name: "passthrough -inf",
|
||
|
In: Color{math.Inf(-1)},
|
||
|
Out: Color{math.Inf(-1)},
|
||
|
}, {
|
||
|
Name: "passthrough nan",
|
||
|
In: Color{math.NaN()},
|
||
|
Out: Color{math.NaN()},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
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, false, midpoint, distance, Model)
|
||
|
}
|