github.com/schollz/clusters@v0.0.0-20221201012527-c6c68863636f/kmeans_test.go (about) 1 package clusters 2 3 import ( 4 "testing" 5 ) 6 7 func TestKmeansClusterNumerMatches(t *testing.T) { 8 const ( 9 C = 8 10 ) 11 12 var ( 13 f = "data/bus-stops.csv" 14 i = CsvImporter() 15 ) 16 17 d, e := i.Import(f, 4, 5) 18 if e != nil { 19 t.Errorf("Error importing data: %s\n", e.Error()) 20 } 21 22 c, e := KMeans(1000, C, EuclideanDistance) 23 if e != nil { 24 t.Errorf("Error initializing kmeans clusterer: %s\n", e.Error()) 25 } 26 27 if e = c.Learn(d); e != nil { 28 t.Errorf("Error learning data: %s\n", e.Error()) 29 } 30 31 if len(c.Sizes()) != C { 32 t.Errorf("Number of clusters does not match: %d vs %d\n", len(c.Sizes()), C) 33 } 34 }