Skip to content

Commit

Permalink
Plus corresponding test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpapathanasiou committed Jun 20, 2021
1 parent 482bcdd commit 97b8465
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions go/simplegraph/visualizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"testing"
)

// Test using the graph from: https://commons.wikimedia.org/wiki/File:Graph_with_Chordless_and_Chorded_Cycles.svg
var (
ids = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
sources = []string{"A", "A", "B", "B", "B", "C", "C", "C", "C", "D", "D", "D", "E", "E", "G", "G", "G", "G", "H", "H", "I", "I", "I", "J", "J", "K", "K", "K", "K", "L", "L", "L"}
targets = []string{"B", "F", "A", "C", "G", "B", "D", "G", "L", "C", "E", "K", "D", "F", "B", "C", "H", "L", "G", "I", "H", "J", "K", "I", "K", "D", "I", "J", "L", "C", "G", "K"}
)

func TestVisualization(t *testing.T) {
file := "testdb.sqlite3"
Initialize(file)
defer os.Remove(file)

/*
Test using the graph from:
https://commons.wikimedia.org/wiki/File:Graph_with_Chordless_and_Chorded_Cycles.svg
*/
nodes := [][]byte{}
ids := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}

l := len(ids)
for i := 0; i < l; i++ {
nodes = append(nodes, []byte(fmt.Sprintf("{\"id\":%q}", ids[i])))
Expand All @@ -27,9 +30,6 @@ func TestVisualization(t *testing.T) {
t.Errorf("AddNode() inserted %d,%q but expected 1,nil", count, err.Error())
}

sources := []string{"A", "A", "B", "B", "B", "C", "C", "C", "C", "D", "D", "D", "E", "E", "G", "G", "G", "G", "H", "H", "I", "I", "I", "J", "J", "K", "K", "K", "K", "L", "L", "L"}
targets := []string{"B", "F", "A", "C", "G", "B", "D", "G", "L", "C", "E", "K", "D", "F", "B", "C", "H", "L", "G", "I", "H", "J", "K", "I", "K", "D", "I", "J", "L", "C", "G", "K"}

count, err = BulkConnectNodes(sources, targets, file)
if count != 1 && err != nil {
t.Errorf("BulkConnectNodes() inserted %d,%q but expected 1,nil", count, err.Error())
Expand All @@ -40,4 +40,14 @@ func TestVisualization(t *testing.T) {
if len(dot) != expected {
t.Errorf("Visualize() produced string of len %d but expected %d", len(dot), expected)
}

bodies, traverseErr := TraverseWithBodiesFromTo("A", "E", TraverseWithBodies, file)
if traverseErr != nil {
t.Errorf("TraverseWithBodiesFromTo() resulted in %q but nil", traverseErr.Error())
}
dot = VisualizeBodies(bodies, file)
expected = 1247
if len(dot) != expected {
t.Errorf("VisualizeBodies() produced string of len %d but expected %d", len(dot), expected)
}
}

0 comments on commit 97b8465

Please sign in to comment.