Skip to content

Commit

Permalink
graph/path: add dominator tree identity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jan 13, 2019
1 parent be78930 commit c1e751e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions graph/path/control_flow_test.go
Expand Up @@ -146,6 +146,17 @@ func TestDominators(t *testing.T) {
{"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) {
t.Errorf("unexpected dominator tree from %s: got:%v want:%v",
alg.name, got.dominatorOf, test.want.dominatorOf)
}

for q, want := range test.want.dominatorOf {
node := got.DominatorOf(q)
if node != want {
Expand All @@ -157,6 +168,12 @@ func TestDominators(t *testing.T) {
for _, nodes := range got.dominatedBy {
sort.Sort(ordered.ByID(nodes))
}

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) {
Expand Down

0 comments on commit c1e751e

Please sign in to comment.