lnd.xprv/routing/rt/graph/dijkstra_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

42 lines
1.3 KiB
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 TestDijkstraPath(t *testing.T) {
g, v := newTestGraph()
tests := []struct {
Source, Target Vertex
ExpectedPath []Vertex
ExpectedWeight float64
}{
{v[1], v[4], []Vertex{v[1], v[7], v[2], v[3], v[6], v[5], v[4]}, 13},
{v[5], v[7], []Vertex{v[5], v[6], v[3], v[2], v[7]}, 10},
}
for _, test := range tests {
// Test DijkstraPath
path, err := DijkstraPath(g, test.Source, test.Target)
if err != nil {
t.Errorf("DijkstraPath(g, %v, %v ) returns not nil error: %v", test.Source, test.Target, err)
}
if !reflect.DeepEqual(path, test.ExpectedPath) {
t.Errorf("DijkstraPath(g, %v, %v ) = %v, want %v", test.Source, test.Target, path, test.ExpectedPath)
}
// Test DijkstraPathWeight
weight, err := DijkstraPathWeight(g, test.Source, test.Target)
if err != nil {
t.Errorf("DijkstraPathWeight(g, %v, %v ) returns not nil error: %v", test.Source, test.Target, err)
}
if weight != test.ExpectedWeight {
t.Errorf("DijkstraPathWeight(g, %v, %v ) = %v, want %v", test.Source, test.Target, weight, test.ExpectedWeight)
}
}
}