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.
101 lines
2.3 KiB
101 lines
2.3 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"strconv"
|
||
5 years ago
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
5 years ago
|
"./correct"
|
||
5 years ago
|
"github.com/01-edu/public/go/lib"
|
||
5 years ago
|
)
|
||
|
|
||
|
type Node7 = student.NodeL
|
||
5 years ago
|
type List7 = correct.List
|
||
|
type NodeS7 = correct.NodeL
|
||
5 years ago
|
type ListS7 = student.List
|
||
|
|
||
|
func listToStringStu8(l *ListS7) string {
|
||
|
var res string
|
||
|
it := l.Head
|
||
|
for it != nil {
|
||
|
switch it.Data.(type) {
|
||
|
case int:
|
||
|
res += strconv.Itoa(it.Data.(int)) + "-> "
|
||
|
case string:
|
||
|
res += it.Data.(string) + "-> "
|
||
|
}
|
||
|
it = it.Next
|
||
|
}
|
||
|
res += "<nil>"
|
||
|
return res
|
||
|
}
|
||
|
|
||
5 years ago
|
func listPushBackTest7(l1 *ListS7, l2 *List7, data interface{}) {
|
||
5 years ago
|
n := &Node7{Data: data}
|
||
|
n1 := &NodeS7{Data: data}
|
||
5 years ago
|
if l1.Head == nil {
|
||
|
l1.Head = n
|
||
5 years ago
|
} else {
|
||
5 years ago
|
iterator := l1.Head
|
||
5 years ago
|
for iterator.Next != nil {
|
||
|
iterator = iterator.Next
|
||
|
}
|
||
|
iterator.Next = n
|
||
|
}
|
||
5 years ago
|
if l2.Head == nil {
|
||
|
l2.Head = n1
|
||
5 years ago
|
} else {
|
||
5 years ago
|
iterator1 := l2.Head
|
||
5 years ago
|
for iterator1.Next != nil {
|
||
|
iterator1 = iterator1.Next
|
||
|
}
|
||
|
iterator1.Next = n1
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func comparFuncList7(l1 *List7, l2 *ListS7, f func(*Node7)) {
|
||
5 years ago
|
funcName := correct.GetName(f)
|
||
5 years ago
|
for l1.Head != nil || l2.Head != nil {
|
||
|
if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) {
|
||
5 years ago
|
lib.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n",
|
||
5 years ago
|
listToStringStu8(l2), correct.ListToString(l1.Head), funcName, l2.Head, l1.Head)
|
||
5 years ago
|
}
|
||
|
if l1.Head.Data != l2.Head.Data {
|
||
5 years ago
|
lib.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n",
|
||
5 years ago
|
listToStringStu8(l2), correct.ListToString(l1.Head), funcName, l2.Head.Data, l1.Head.Data)
|
||
5 years ago
|
}
|
||
|
l1.Head = l1.Head.Next
|
||
5 years ago
|
l2.Head = l2.Head.Next
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
// applies a function to the correct.ListS
|
||
5 years ago
|
func main() {
|
||
|
link1 := &List7{}
|
||
5 years ago
|
link2 := &ListS7{}
|
||
5 years ago
|
table := []correct.NodeTest{}
|
||
|
table = correct.ElementsToTest(table)
|
||
5 years ago
|
table = append(table,
|
||
5 years ago
|
correct.NodeTest{
|
||
5 years ago
|
Data: []interface{}{"I", 1, "something", 2},
|
||
|
},
|
||
|
)
|
||
|
for _, arg := range table {
|
||
|
for i := 0; i < len(arg.Data); i++ {
|
||
5 years ago
|
listPushBackTest7(link2, link1, arg.Data[i])
|
||
5 years ago
|
}
|
||
|
student.ListForEach(link2, student.Add2_node)
|
||
5 years ago
|
correct.ListForEach(link1, correct.Add2_node)
|
||
5 years ago
|
|
||
5 years ago
|
comparFuncList7(link1, link2, student.Add2_node)
|
||
5 years ago
|
|
||
|
student.ListForEach(link2, student.Subtract3_node)
|
||
5 years ago
|
correct.ListForEach(link1, correct.Subtract3_node)
|
||
5 years ago
|
|
||
5 years ago
|
comparFuncList7(link1, link2, student.Subtract3_node)
|
||
5 years ago
|
|
||
5 years ago
|
link1 = &List7{}
|
||
5 years ago
|
link2 = &ListS7{}
|
||
|
}
|
||
|
}
|