diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a4d1d..a63729e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ The format is based on Keep a Changelog and this project adheres to Semantic Ver - pkg.go.dev Examples: `ExampleNewKDTreeFromDim_Insert`, `ExampleKDTree_TiesBehavior`, `ExampleKDTree_Radius_none`. - Lint: enable `errcheck` in `.golangci.yml` with test-file exclusion to reduce noise. - CI: enable module cache in `actions/setup-go` to speed up workflows. -- Docs: README cross-link to Performance page and add a concise “Choosing a metric” tip section. + +### Fixed +- go vet failures in examples due to misnamed `Example*` functions; renamed to avoid referencing non-existent methods and identifiers. +- Stabilized `ExampleKDTree_Nearest` to avoid a tie case; adjusted query and expected output. +- Relaxed floating-point equality in `TestWeightedCosineDistance_Basics` to use an epsilon, avoiding spurious failures on some toolchains. ## [0.3.0] - 2025-11-03 ### Added diff --git a/examples_test.go b/examples_test.go index 4a7a100..6e28500 100644 --- a/examples_test.go +++ b/examples_test.go @@ -40,9 +40,9 @@ func ExampleKDTree_Nearest() { {ID: "y", Coords: []float64{2, 0}, Value: 2}, } tr, _ := poindexter.NewKDTree(pts, poindexter.WithMetric(poindexter.EuclideanDistance{})) - p, d, ok := tr.Nearest([]float64{1, 0}) + p, d, ok := tr.Nearest([]float64{1.4, 0}) fmt.Printf("ok=%v id=%s d=%.1f", ok, p.ID, d) - // Output: ok=true id=y d=1.0 + // Output: ok=true id=y d=0.6 } func ExampleKDTree_KNearest() { @@ -69,7 +69,7 @@ func ExampleKDTree_Radius() { // Output: 2 a b } -func ExampleKDTree_InsertDeleteByID() { +func ExampleKDTree_DeleteByID() { pts := []poindexter.KDPoint[string]{ {ID: "A", Coords: []float64{0}, Value: "a"}, } @@ -204,7 +204,7 @@ func ExampleBuild4DWithStats() { // Output: 4 } -func ExampleNewKDTreeFromDim_Insert() { +func ExampleNewKDTreeFromDim() { // Construct an empty 2D tree, insert a point, then query. tr, _ := poindexter.NewKDTreeFromDim[string](2) tr.Insert(poindexter.KDPoint[string]{ID: "A", Coords: []float64{0.1, 0.2}, Value: "alpha"}) @@ -213,7 +213,7 @@ func ExampleNewKDTreeFromDim_Insert() { // Output: ok=true id=A dim=2 len=1 } -func ExampleKDTree_TiesBehavior() { +func Example_tiesBehavior() { // Two points equidistant from the query; tie ordering is arbitrary, // but distances are equal. pts := []poindexter.KDPoint[int]{ diff --git a/kdtree_nd_test.go b/kdtree_nd_test.go index 66e8927..c64f899 100644 --- a/kdtree_nd_test.go +++ b/kdtree_nd_test.go @@ -47,8 +47,9 @@ func TestWeightedCosineDistance_Basics(t *testing.T) { a := []float64{1, 0} b := []float64{1, 0} d := w.Distance(a, b) - if d != 0 { - t.Fatalf("expected 0, got %v", d) + // allow tiny floating-point noise + if d > 1e-12 { + t.Fatalf("expected ~0, got %v", d) } // orthogonal remains ~1 regardless of weights for these axes b = []float64{0, 3}