mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-17 16:49:04 +00:00
Split the catch-all values.go into one file per concept, each mirrored by its test: distance.go, norm.go, stats.go, product.go, centroid.go, plus the mean methods folded into mean.go and Copy/Dim/Sum into vector.go. Remove values.go, values_test.go, and values_more_test.go so functionality and tests live where developers expect them. Hoist the two 512-dimensional face embeddings shared by the distance, norm, and cosine tests into fixtures_test.go, removing the previous triplication, and decompose the monolithic TestVector into per-concept tests. Close pre-existing coverage gaps in the integer converters and the GeometricMean/HarmonicMean method wrappers, bringing the package to 100% statement coverage. Pure code movement; no behavior change.
39 lines
1 KiB
Go
39 lines
1 KiB
Go
package vector
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCentroid(t *testing.T) {
|
|
t.Run("Mean", func(t *testing.T) {
|
|
got := Centroid(Vectors{{1, 2}, {3, 4}})
|
|
assert.Equal(t, Vector{2, 3}, got)
|
|
})
|
|
t.Run("Single", func(t *testing.T) {
|
|
got := Centroid(Vectors{{2, 4, 6}})
|
|
assert.Equal(t, Vector{2, 4, 6}, got)
|
|
})
|
|
t.Run("SkipsMismatchedDimensions", func(t *testing.T) {
|
|
// The 3-D vector is ignored; the mean is taken over the two 2-D vectors.
|
|
got := Centroid(Vectors{{1, 2}, {1, 2, 3}, {3, 4}})
|
|
assert.Equal(t, Vector{2, 3}, got)
|
|
})
|
|
t.Run("Empty", func(t *testing.T) {
|
|
assert.Nil(t, Centroid(Vectors{}))
|
|
assert.Nil(t, Centroid(nil))
|
|
})
|
|
t.Run("FirstVectorEmpty", func(t *testing.T) {
|
|
assert.Nil(t, Centroid(Vectors{{}, {1, 2}}))
|
|
})
|
|
t.Run("Independent", func(t *testing.T) {
|
|
a := Vector{1, 2}
|
|
b := Vector{3, 4}
|
|
got := Centroid(Vectors{a, b})
|
|
got[0] = 100
|
|
// Mutating the result must not change the inputs.
|
|
assert.Equal(t, Vector{1, 2}, a)
|
|
assert.Equal(t, Vector{3, 4}, b)
|
|
})
|
|
}
|