mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-18 00:59:38 +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.
34 lines
785 B
Go
34 lines
785 B
Go
package vector
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestProduct(t *testing.T) {
|
|
t.Run("Values", func(t *testing.T) {
|
|
p, err := Product(Vector{1, 2, 3}, Vector{4, 5, 6})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, Vector{4, 10, 18}, p)
|
|
})
|
|
t.Run("LengthMismatch", func(t *testing.T) {
|
|
p, err := Product(Vector{1, 2, 3}, Vector{4, 5})
|
|
assert.Error(t, err)
|
|
assert.Nil(t, p)
|
|
})
|
|
}
|
|
|
|
func TestDotProduct(t *testing.T) {
|
|
t.Run("Values", func(t *testing.T) {
|
|
r, err := DotProduct(Vector{1, 2, 3}, Vector{4, 5, 6})
|
|
assert.NoError(t, err)
|
|
assert.InDelta(t, 32.0, r, 0.00001)
|
|
})
|
|
t.Run("LengthMismatch", func(t *testing.T) {
|
|
r, err := DotProduct(Vector{1, 2, 3}, Vector{4, 5})
|
|
assert.Error(t, err)
|
|
assert.True(t, math.IsNaN(r))
|
|
})
|
|
}
|