2017-10-27 17:25:20 +02:00
|
|
|
package treerack
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func checkNodes(t *testing.T, ignorePosition bool, left, right []*Node) {
|
|
|
|
if len(left) != len(right) {
|
|
|
|
t.Error("length doesn't match", len(left), len(right))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for len(left) > 0 {
|
|
|
|
checkNode(t, ignorePosition, left[0], right[0])
|
|
|
|
if t.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
left, right = left[1:], right[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkNode(t *testing.T, ignorePosition bool, left, right *Node) {
|
|
|
|
if (left == nil) != (right == nil) {
|
|
|
|
t.Error("nil reference doesn't match", left == nil, right == nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if left == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if left.Name != right.Name {
|
|
|
|
t.Error("name doesn't match", left.Name, right.Name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ignorePosition && left.From != right.From {
|
|
|
|
t.Error("from doesn't match", left.Name, left.From, right.From)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ignorePosition && left.To != right.To {
|
|
|
|
t.Error("to doesn't match", left.Name, left.To, right.To)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-04 22:08:15 +01:00
|
|
|
lnodes, rnodes := left.Nodes, right.Nodes
|
|
|
|
if len(lnodes) != len(rnodes) {
|
|
|
|
t.Error("length doesn't match", left.Name, len(lnodes), len(rnodes))
|
2017-10-27 17:25:20 +02:00
|
|
|
t.Log(left)
|
|
|
|
t.Log(right)
|
|
|
|
for {
|
2017-11-04 22:08:15 +01:00
|
|
|
if len(lnodes) > 0 {
|
|
|
|
t.Log("<", lnodes[0])
|
|
|
|
lnodes = lnodes[1:]
|
2017-10-27 17:25:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 22:08:15 +01:00
|
|
|
if len(rnodes) > 0 {
|
|
|
|
t.Log(">", rnodes[0])
|
|
|
|
rnodes = rnodes[1:]
|
2017-10-27 17:25:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 22:08:15 +01:00
|
|
|
if len(lnodes) == 0 && len(rnodes) == 0 {
|
2017-10-27 17:25:20 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-04 22:08:15 +01:00
|
|
|
checkNodes(t, ignorePosition, lnodes, rnodes)
|
2017-10-27 17:25:20 +02:00
|
|
|
}
|