lnd.xprv/routing/rt/graph/bfs_test.go
BitfuryLightning 327768f4ad routing: Move tools inside lnd. Refactor and delete unneeded stuff
Use [33]byte for graph vertex representation.
Delete unneeded stuff:
1. DeepEqual for graph comparison
2. EdgePath
3. 2-thread BFS
4. Table transfer messages and neighborhood radius
5. Beacons

Refactor:
1. Change ID to Vertex
2. Test use table driven approach
3. Add comments
4. Make graph internal representation private
5. Use wire.OutPoint as  EdgeId
6. Decouple routing messages from routing implementation
7. Delete Async methods
8. Delete unneeded channels and priority buffer from manager
9. Delete unneeded interfaces in internal graph realisation
10. Renamed ID to Vertex
2016-11-23 20:37:43 -06:00

32 lines
854 B
Go

// Copyright (c) 2016 Bitfury Group Limited
// Distributed under the MIT software license, see the accompanying
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
package graph
import (
"reflect"
"testing"
)
func TestShortestPath(t *testing.T) {
g, v := newTestGraph()
tests := []struct{
Source, Target Vertex
ExpectedPath []Vertex
}{
{v[1], v[4], []Vertex{v[1], v[7], v[3], v[6], v[5], v[4]}},
{v[5], v[7], []Vertex{v[5], v[6], v[3], v[7]}},
}
for _, test := range tests {
path, err := ShortestPath(g, test.Source, test.Target)
if err != nil {
t.Errorf("ShortestPath(g, %v, %v ) returns not nil error: %v", test.Source, test.Target, err)
}
if !reflect.DeepEqual(path, test.ExpectedPath) {
t.Errorf("ShortestPath(g, %v, %v ) = %v, want %v", test.Source, test.Target, path, test.ExpectedPath)
}
}
}