mirror of
https://github.com/gonum/gonum.git
synced 2025-10-19 05:24:52 +08:00
graph/flow: improve consistency of coverage reports
This commit is contained in:
@@ -132,53 +132,60 @@ func (n char) ID() int64 { return int64(n) }
|
|||||||
func (n char) String() string { return string(n) }
|
func (n char) String() string { return string(n) }
|
||||||
|
|
||||||
func TestDominators(t *testing.T) {
|
func TestDominators(t *testing.T) {
|
||||||
for _, test := range dominatorsTests {
|
// The dominator functions are non-deterministic due
|
||||||
g := simple.NewDirectedGraph()
|
// to map iteration ordering, so repeat the tests to
|
||||||
for _, e := range test.edges {
|
// ensure consistent coverage. The value of 100 was
|
||||||
g.SetEdge(e)
|
// chosen empirically to have no observed reduction
|
||||||
}
|
// in coverage in several hundred runs of go test -cover.
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
for _, alg := range []struct {
|
for _, test := range dominatorsTests {
|
||||||
name string
|
g := simple.NewDirectedGraph()
|
||||||
fn func(graph.Node, graph.Directed) DominatorTree
|
for _, e := range test.edges {
|
||||||
}{
|
g.SetEdge(e)
|
||||||
{"Dominators", Dominators},
|
|
||||||
{"DominatorsSLT", DominatorsSLT},
|
|
||||||
} {
|
|
||||||
got := alg.fn(test.n, g)
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(got.Root(), test.want.root) {
|
|
||||||
t.Errorf("unexpected dominator tree root from %s: got:%v want:%v",
|
|
||||||
alg.name, got.root, test.want.root)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(got.dominatorOf, test.want.dominatorOf) {
|
for _, alg := range []struct {
|
||||||
t.Errorf("unexpected dominator tree from %s: got:%v want:%v",
|
name string
|
||||||
alg.name, got.dominatorOf, test.want.dominatorOf)
|
fn func(graph.Node, graph.Directed) DominatorTree
|
||||||
}
|
}{
|
||||||
|
{"Dominators", Dominators},
|
||||||
|
{"DominatorsSLT", DominatorsSLT},
|
||||||
|
} {
|
||||||
|
got := alg.fn(test.n, g)
|
||||||
|
|
||||||
for q, want := range test.want.dominatorOf {
|
if !reflect.DeepEqual(got.Root(), test.want.root) {
|
||||||
node := got.DominatorOf(q)
|
t.Errorf("unexpected dominator tree root from %s: got:%v want:%v",
|
||||||
if node != want {
|
alg.name, got.root, test.want.root)
|
||||||
t.Errorf("unexpected dominator tree result from %s dominated of %v: got:%v want:%v",
|
|
||||||
alg.name, q, node, want)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, nodes := range got.dominatedBy {
|
if !reflect.DeepEqual(got.dominatorOf, test.want.dominatorOf) {
|
||||||
sort.Sort(ordered.ByID(nodes))
|
t.Errorf("unexpected dominator tree from %s: got:%v want:%v",
|
||||||
}
|
alg.name, got.dominatorOf, test.want.dominatorOf)
|
||||||
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(got.dominatedBy, test.want.dominatedBy) {
|
for q, want := range test.want.dominatorOf {
|
||||||
t.Errorf("unexpected dominator tree from %s: got:%v want:%v",
|
node := got.DominatorOf(q)
|
||||||
alg.name, got.dominatedBy, test.want.dominatedBy)
|
if node != want {
|
||||||
}
|
t.Errorf("unexpected dominator tree result from %s dominated of %v: got:%v want:%v",
|
||||||
|
alg.name, q, node, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for q, want := range test.want.dominatedBy {
|
for _, nodes := range got.dominatedBy {
|
||||||
nodes := got.DominatedBy(q)
|
sort.Sort(ordered.ByID(nodes))
|
||||||
if !reflect.DeepEqual(nodes, want) {
|
}
|
||||||
t.Errorf("unexpected dominator tree result from %s dominated by %v: got:%v want:%v",
|
|
||||||
alg.name, q, nodes, want)
|
if !reflect.DeepEqual(got.dominatedBy, test.want.dominatedBy) {
|
||||||
|
t.Errorf("unexpected dominator tree from %s: got:%v want:%v",
|
||||||
|
alg.name, got.dominatedBy, test.want.dominatedBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
for q, want := range test.want.dominatedBy {
|
||||||
|
nodes := got.DominatedBy(q)
|
||||||
|
if !reflect.DeepEqual(nodes, want) {
|
||||||
|
t.Errorf("unexpected dominator tree result from %s dominated by %v: got:%v want:%v",
|
||||||
|
alg.name, q, nodes, want)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user