package lrgba

import (
	"math"
	"testing"

	"smariot.com/color/internal/helper"
)

func eq(c0, c1 Color) bool {
	return helper.EqFloat64SliceFuzzy(
		[]float64{c0.R, c0.G, c0.B, c0.A},
		[]float64{c1.R, c1.G, c1.B, c1.A},
	)
}

func midpoint(c0, c1 Color) Color {
	return Color{(c0.R + c1.R) / 2, (c0.G + c1.G) / 2, (c0.B + c1.B) / 2, (c0.A + c1.A) / 2}
}

func TestModel(t *testing.T) {
	helper.TestModel(t, true, true, Model, eq, []helper.ConvertTest[Color]{
		{
			Name: "passthrough",
			// These is a very illegal colour. If it makes it through
			// unchanged, we can be reasonably confident no colour space conversions were
			// attempted.
			In:  Color{math.Inf(1), math.Inf(-1), math.NaN(), 0},
			Out: Color{math.Inf(1), math.Inf(-1), math.NaN(), 0},
		},
	})
}

func TestDistance(t *testing.T) {
	helper.TestDistance(t, true, true, midpoint, Distance, Model)
}