github.com/LdDl/ch@v1.7.8/import_test.go (about)

     1  package ch
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  func TestImportedFileShortestPath(t *testing.T) {
     9  	g, err := ImportFromFile("data/export_pgrouting.csv", "data/export_pgrouting_vertices.csv", "data/export_pgrouting_shortcuts.csv")
    10  	if err != nil {
    11  		t.Error(err)
    12  		return
    13  	}
    14  	t.Log("TestImportedFileShortestPath is starting...")
    15  	u := int64(69618)
    16  	v := int64(5924)
    17  
    18  	correctNumShortcuts := int64(394840)
    19  	correctNumVertices := 187853
    20  	evaluatedShortcuts := g.GetShortcutsNum()
    21  	if evaluatedShortcuts != correctNumShortcuts {
    22  		t.Errorf("Number of contractions should be %d, but got %d", correctNumShortcuts, evaluatedShortcuts)
    23  	}
    24  	if len(g.Vertices) != correctNumVertices {
    25  		t.Errorf("Number of vertices should be %d, but got %d", correctNumVertices, len(g.Vertices))
    26  	}
    27  
    28  	ans, path := g.ShortestPath(u, v)
    29  	if len(path) != 160 {
    30  		t.Errorf("Num of vertices in path should be 160, but got %d", len(path))
    31  		return
    32  	}
    33  	correctCost := 19135.6581215226
    34  	if math.Abs(ans-correctCost) > eps {
    35  		t.Errorf("Cost of path should be %f, but got %f", correctCost, ans)
    36  		return
    37  	}
    38  	t.Log("TestImportedFileShortestPath is Ok!")
    39  }