Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/01-edu/z01"
|
|
|
|
|
|
|
|
correct "./correct"
|
|
|
|
student "./student"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BTreeMinStu(root *student.TreeNode) *student.TreeNode {
|
|
|
|
if root == nil || root.Left == nil {
|
|
|
|
return root
|
|
|
|
}
|
|
|
|
return BTreeMinStu(root.Left)
|
|
|
|
}
|
|
|
|
|
|
|
|
func errorMessage_isbin(fn interface{}, root, a *correct.TreeNode, b *student.TreeNode) {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
z01.Fatalf("%s(\n%s\n) == %s instead of %s\n",
|
|
|
|
"BTreeIsBinary",
|
|
|
|
correct.FormatTree(root),
|
|
|
|
b.Data,
|
|
|
|
a.Data,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CompareNode_isbin(fn interface{}, arg1, a *correct.TreeNode, b *student.TreeNode) {
|
|
|
|
if a == nil || b == nil {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
z01.Fatalf("Expected %v instead of %v\n", a, b)
|
|
|
|
}
|
|
|
|
if a.Data != b.Data {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
errorMessage_isbin(fn, arg1, a, b)
|
|
|
|
}
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
if a.Parent != nil && b.Parent != nil && a.Parent.Data != b.Parent.Data {
|
|
|
|
errorMessage_isbin(fn, arg1, a, b)
|
|
|
|
z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data)
|
|
|
|
}
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) {
|
|
|
|
z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent)
|
|
|
|
}
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
if a.Right != nil && b.Right != nil && a.Right.Data != b.Right.Data {
|
|
|
|
errorMessage_isbin(fn, arg1, a, b)
|
|
|
|
z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data)
|
|
|
|
}
|
|
|
|
if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) {
|
|
|
|
z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right)
|
|
|
|
}
|
|
|
|
if a.Left != nil && b.Left != nil && a.Left.Data != b.Left.Data {
|
|
|
|
errorMessage_isbin(fn, arg1, a, b)
|
|
|
|
z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left)
|
|
|
|
}
|
|
|
|
if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) {
|
|
|
|
z01.Fatalf("Expected left child value %v instead of %v\n", a, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CompareReturn_isbin(fn1, fn2 interface{}, arg1 *correct.TreeNode, arg2 interface{}) {
|
|
|
|
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 *correct.TreeNode:
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
CompareNode_isbin(fn1, arg1, str, out2.Results[i].(*student.TreeNode))
|
|
|
|
default:
|
|
|
|
if !reflect.DeepEqual(str, out2.Results[i]) {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
z01.Fatalf("%s(\n%s) == %s instead of %s\n",
|
|
|
|
"BTreeIsBinary",
|
|
|
|
correct.FormatTree(arg1),
|
|
|
|
z01.Format(out2.Results...),
|
|
|
|
z01.Format(out1.Results...),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
func main() {
|
|
|
|
root := &correct.TreeNode{Data: "04"}
|
|
|
|
rootS := &student.TreeNode{Data: "04"}
|
|
|
|
|
|
|
|
ins := []string{"01", "07", "05", "12", "02", "03", "10"}
|
|
|
|
|
|
|
|
for _, v := range ins {
|
|
|
|
root = correct.BTreeInsertData(root, v)
|
|
|
|
rootS = student.BTreeInsertData(rootS, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
CompareReturn_isbin(correct.BTreeIsBinary, student.BTreeIsBinary, root, rootS)
|
|
|
|
|
|
|
|
rootNB := &correct.TreeNode{Data: "04"}
|
|
|
|
rootNB_stu := &student.TreeNode{Data: "04"}
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
// Test a non-binarysearch tree
|
|
|
|
for _, v := range ins {
|
|
|
|
rootNB = correct.BTreeInsertData(rootNB, v)
|
|
|
|
rootNB_stu = student.BTreeInsertData(rootNB_stu, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
min := correct.BTreeMin(rootNB)
|
|
|
|
minStu := BTreeMinStu(rootNB_stu)
|
|
|
|
|
|
|
|
min.Left = &correct.TreeNode{Data: "123"}
|
|
|
|
minStu.Left = &student.TreeNode{Data: "123"}
|
|
|
|
|
|
|
|
CompareReturn_isbin(correct.BTreeIsBinary, student.BTreeIsBinary, rootNB, rootNB_stu)
|
|
|
|
}
|