mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.5 KiB
96 lines
2.5 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
|
||
|
solutions "./solutions"
|
||
|
student "./student"
|
||
|
|
||
|
"github.com/01-edu/z01"
|
||
|
)
|
||
|
|
||
5 years ago
|
func errorMessage_min(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) {
|
||
|
z01.Fatalf("%s(\n%s) == %s instead of %s\n",
|
||
|
"BTreeMin",
|
||
5 years ago
|
solutions.FormatTree(root),
|
||
|
b.Data,
|
||
|
a.Data,
|
||
|
)
|
||
|
}
|
||
|
|
||
5 years ago
|
func CompareNode_min(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) {
|
||
5 years ago
|
if a == nil || b == nil {
|
||
5 years ago
|
z01.Fatalf("Expected %v instead of %v\n", a, b)
|
||
5 years ago
|
return
|
||
|
}
|
||
|
|
||
|
if a.Data != b.Data {
|
||
5 years ago
|
errorMessage_min(fn, arg1, a, b)
|
||
5 years ago
|
}
|
||
|
|
||
|
if a.Parent != nil && b.Parent != nil {
|
||
|
if a.Parent.Data != b.Parent.Data {
|
||
5 years ago
|
errorMessage_min(fn, arg1, a, b)
|
||
|
z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data)
|
||
5 years ago
|
}
|
||
|
} else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) {
|
||
5 years ago
|
z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent)
|
||
5 years ago
|
}
|
||
|
|
||
|
if a.Right != nil && b.Right != nil {
|
||
|
if a.Right.Data != b.Right.Data {
|
||
5 years ago
|
errorMessage_min(fn, arg1, a, b)
|
||
|
z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data)
|
||
5 years ago
|
}
|
||
|
} else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) {
|
||
5 years ago
|
z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right)
|
||
5 years ago
|
}
|
||
|
|
||
|
if a.Left != nil && b.Left != nil {
|
||
|
if a.Left.Data != b.Left.Data {
|
||
5 years ago
|
errorMessage_min(fn, arg1, a, b)
|
||
|
z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left)
|
||
5 years ago
|
}
|
||
|
} else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) {
|
||
5 years ago
|
z01.Fatalf("Expected left child value %v instead of %v\n", a, b)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func CompareReturn_min(fn1, fn2, arg1, arg2 interface{}) {
|
||
5 years ago
|
arar1 := []interface{}{arg1}
|
||
|
arar2 := []interface{}{arg2}
|
||
|
|
||
|
out1 := z01.Monitor(fn1, arar1)
|
||
|
out2 := z01.Monitor(fn2, arar2)
|
||
|
|
||
|
for i, v := range out1.Results {
|
||
|
switch str := v.(type) {
|
||
|
case *solutions.TreeNode:
|
||
5 years ago
|
CompareNode_min(fn1, arg1.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode))
|
||
5 years ago
|
default:
|
||
|
if !reflect.DeepEqual(str, out2.Results[i]) {
|
||
5 years ago
|
z01.Fatalf("%s(%s) == %s instead of %s\n",
|
||
|
"BTreeMin",
|
||
5 years ago
|
z01.Format(arg1),
|
||
|
z01.Format(out2.Results...),
|
||
|
z01.Format(out1.Results...),
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
root := &solutions.TreeNode{Data: "04"}
|
||
|
rootS := &student.TreeNode{Data: "04"}
|
||
|
|
||
|
ins := []string{"03", "02", "01", "07", "05", "12", "10"}
|
||
|
|
||
|
for _, v := range ins {
|
||
|
root = solutions.BTreeInsertData(root, v)
|
||
|
rootS = student.BTreeInsertData(rootS, v)
|
||
|
}
|
||
|
|
||
5 years ago
|
CompareReturn_min(solutions.BTreeMin, student.BTreeMin, root, rootS)
|
||
5 years ago
|
}
|