|
|
@ -1,11 +1,12 @@ |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"math/rand" |
|
|
|
"math/rand" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"github.com/01-edu/z01" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
solutions "../../solutions" |
|
|
|
solutions "../../solutions" |
|
|
|
|
|
|
|
"github.com/01-edu/z01" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type stuTreeNode = TreeNodeL |
|
|
|
type stuTreeNode = TreeNodeL |
|
|
@ -48,40 +49,39 @@ func New(n, k int) (*solTreeNode, *stuTreeNode, *solTreeNode) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func returnSolTree(root *solTreeNode) string { |
|
|
|
func returnSolTree(root *solTreeNode) string { |
|
|
|
if (root == nil) { |
|
|
|
if root == nil { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
ans := strconv.Itoa(root.Val) |
|
|
|
ans := strconv.Itoa(root.Val) |
|
|
|
if (root.Left == nil && root.Right == nil) {
|
|
|
|
if root.Left == nil && root.Right == nil { |
|
|
|
return ans |
|
|
|
return ans |
|
|
|
} |
|
|
|
} |
|
|
|
if (root.Left != nil) { |
|
|
|
if root.Left != nil { |
|
|
|
ans += " " + returnSolTree(root.Left) |
|
|
|
ans += " " + returnSolTree(root.Left) |
|
|
|
} |
|
|
|
} |
|
|
|
if (root.Right != nil) { |
|
|
|
if root.Right != nil { |
|
|
|
ans += " " + returnSolTree(root.Right) |
|
|
|
ans += " " + returnSolTree(root.Right) |
|
|
|
} |
|
|
|
} |
|
|
|
return ans |
|
|
|
return ans |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func returnStuTree(root *stuTreeNode) string { |
|
|
|
func returnStuTree(root *stuTreeNode) string { |
|
|
|
if (root == nil) { |
|
|
|
if root == nil { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
ans := strconv.Itoa(root.Val) |
|
|
|
ans := strconv.Itoa(root.Val) |
|
|
|
if (root.Left == nil && root.Right == nil) {
|
|
|
|
if root.Left == nil && root.Right == nil { |
|
|
|
return ans |
|
|
|
return ans |
|
|
|
} |
|
|
|
} |
|
|
|
if (root.Left != nil) { |
|
|
|
if root.Left != nil { |
|
|
|
ans += " " + returnStuTree(root.Left) |
|
|
|
ans += " " + returnStuTree(root.Left) |
|
|
|
} |
|
|
|
} |
|
|
|
if (root.Right != nil) { |
|
|
|
if root.Right != nil { |
|
|
|
ans += " " + returnStuTree(root.Right) |
|
|
|
ans += " " + returnStuTree(root.Right) |
|
|
|
} |
|
|
|
} |
|
|
|
return ans |
|
|
|
return ans |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func compareResults(t *testing.T, stuResult, solResult bool, solTree1, solTree2 *solTreeNode) { |
|
|
|
func compareResults(t *testing.T, stuResult, solResult bool, solTree1, solTree2 *solTreeNode) { |
|
|
|
if stuResult != solResult { |
|
|
|
if stuResult != solResult { |
|
|
|
tree1 := returnSolTree(solTree1) |
|
|
|
tree1 := returnSolTree(solTree1) |
|
|
@ -121,4 +121,3 @@ func TestMerge(t *testing.T) { |
|
|
|
compareResults(t, stuResult, solResult, cop1, cop1) |
|
|
|
compareResults(t, stuResult, solResult, cop1, cop1) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|