github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/clustering/agglo_test.go (about) 1 package clustering 2 3 import ( 4 "math" 5 "reflect" 6 "testing" 7 ) 8 9 // TODO(amit): Add more test cases. 10 11 func TestClink(t *testing.T) { 12 points := []float64{0, 1, 5} 13 steps := []AggloStep{ 14 {0, 1, 1}, 15 {1, 2, 5}, 16 } 17 agg := clink(len(points), func(i, j int) float64 { 18 return math.Abs(points[i] - points[j]) 19 }) 20 if agg.Len() != len(points)-1 { 21 t.Fatalf("Len()=%v, want %v", agg.Len(), len(points)-1) 22 } 23 for i := range steps { 24 if step := agg.Step(i); !reflect.DeepEqual(steps[i], step) { 25 t.Errorf("Step(%v)=%v, want %v", i, step, steps[i]) 26 } 27 } 28 } 29 30 func TestSlink(t *testing.T) { 31 points := []float64{0, 1, 5} 32 steps := []AggloStep{ 33 {0, 1, 1}, 34 {1, 2, 4}, 35 } 36 agg := slink(len(points), func(i, j int) float64 { 37 return math.Abs(points[i] - points[j]) 38 }) 39 if agg.Len() != len(points)-1 { 40 t.Fatalf("Len()=%v, want %v", agg.Len(), len(points)-1) 41 } 42 for i := range steps { 43 if step := agg.Step(i); !reflect.DeepEqual(steps[i], step) { 44 t.Errorf("Step(%v)=%v, want %v", i, step, steps[i]) 45 } 46 } 47 }