2015-01-23 17:01:58 -06:00
|
|
|
package dag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGraph_empty(t *testing.T) {
|
|
|
|
var g Graph
|
|
|
|
g.Add(1)
|
|
|
|
g.Add(2)
|
|
|
|
g.Add(3)
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphEmptyStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGraph_basic(t *testing.T) {
|
|
|
|
var g Graph
|
|
|
|
g.Add(1)
|
|
|
|
g.Add(2)
|
|
|
|
g.Add(3)
|
|
|
|
g.Connect(BasicEdge(1, 3))
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 14:56:03 -06:00
|
|
|
func TestGraph_remove(t *testing.T) {
|
|
|
|
var g Graph
|
|
|
|
g.Add(1)
|
|
|
|
g.Add(2)
|
|
|
|
g.Add(3)
|
|
|
|
g.Connect(BasicEdge(1, 3))
|
|
|
|
g.Remove(3)
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphRemoveStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-07 17:37:17 -06:00
|
|
|
func TestGraph_replace(t *testing.T) {
|
|
|
|
var g Graph
|
|
|
|
g.Add(1)
|
|
|
|
g.Add(2)
|
|
|
|
g.Add(3)
|
|
|
|
g.Connect(BasicEdge(1, 2))
|
|
|
|
g.Connect(BasicEdge(2, 3))
|
|
|
|
g.Replace(2, 42)
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testGraphReplaceStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 17:01:58 -06:00
|
|
|
const testGraphBasicStr = `
|
|
|
|
1
|
|
|
|
3
|
|
|
|
2
|
|
|
|
3
|
|
|
|
`
|
2015-02-07 17:37:17 -06:00
|
|
|
|
2015-01-23 17:01:58 -06:00
|
|
|
const testGraphEmptyStr = `
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
`
|
2015-01-30 14:56:03 -06:00
|
|
|
|
|
|
|
const testGraphRemoveStr = `
|
|
|
|
1
|
|
|
|
2
|
|
|
|
`
|
2015-02-07 17:37:17 -06:00
|
|
|
|
|
|
|
const testGraphReplaceStr = `
|
|
|
|
1
|
|
|
|
42
|
|
|
|
3
|
|
|
|
42
|
|
|
|
3
|
|
|
|
`
|