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.
140 lines
2.9 KiB
140 lines
2.9 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/func/correct"
|
||
4 years ago
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/lib"
|
||
5 years ago
|
)
|
||
|
|
||
4 years ago
|
type (
|
||
|
Node11 = student.NodeL
|
||
|
List11 = correct.List
|
||
|
NodeS11 = correct.NodeL
|
||
|
ListS11 = student.List
|
||
|
)
|
||
5 years ago
|
|
||
|
func listToStringStu(l *ListS11) 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 listPushBackTest11(l1 *ListS11, l2 *List11, data interface{}) {
|
||
|
n1 := &Node11{Data: data}
|
||
|
n2 := &NodeS11{Data: data}
|
||
5 years ago
|
|
||
5 years ago
|
if l1.Head == nil {
|
||
|
l1.Head = n1
|
||
5 years ago
|
} else {
|
||
5 years ago
|
iterator := l1.Head
|
||
5 years ago
|
for iterator.Next != nil {
|
||
|
iterator = iterator.Next
|
||
|
}
|
||
5 years ago
|
iterator.Next = n1
|
||
5 years ago
|
}
|
||
5 years ago
|
l1.Tail = n1
|
||
5 years ago
|
|
||
5 years ago
|
if l2.Head == nil {
|
||
|
l2.Head = n2
|
||
5 years ago
|
} else {
|
||
5 years ago
|
iterator1 := l2.Head
|
||
5 years ago
|
for iterator1.Next != nil {
|
||
|
iterator1 = iterator1.Next
|
||
|
}
|
||
5 years ago
|
iterator1.Next = n2
|
||
5 years ago
|
}
|
||
5 years ago
|
l2.Tail = n2
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
func comparFuncList11(l1 *List11, l2 *ListS11) {
|
||
|
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\n\nListMerge() == %v instead of %v\n\n",
|
||
5 years ago
|
listToStringStu(l2), correct.ListToString(l1.Head), l2.Head, l1.Head)
|
||
5 years ago
|
}
|
||
|
if l1.Head.Data != l2.Head.Data {
|
||
5 years ago
|
lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n",
|
||
5 years ago
|
listToStringStu(l2), correct.ListToString(l1.Head), 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
|
func main() {
|
||
|
link1 := &List11{}
|
||
5 years ago
|
linkTest := &List11{}
|
||
|
link2 := &ListS11{}
|
||
|
link2Test := &ListS11{}
|
||
|
|
||
|
type nodeTest struct {
|
||
5 years ago
|
data1 []interface{}
|
||
5 years ago
|
data2 []interface{}
|
||
|
}
|
||
|
table := []nodeTest{}
|
||
|
// empty list
|
||
|
table = append(table,
|
||
|
nodeTest{
|
||
5 years ago
|
data1: []interface{}{},
|
||
5 years ago
|
data2: []interface{}{},
|
||
|
})
|
||
|
table = append(table,
|
||
|
nodeTest{
|
||
5 years ago
|
data1: correct.ConvertIntToInterface(lib.MultRandInt()),
|
||
5 years ago
|
data2: []interface{}{},
|
||
|
})
|
||
|
// jut ints
|
||
|
for i := 0; i < 3; i++ {
|
||
|
val := nodeTest{
|
||
5 years ago
|
data1: correct.ConvertIntToInterface(lib.MultRandInt()),
|
||
|
data2: correct.ConvertIntToInterface(lib.MultRandInt()),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
// just strings
|
||
|
for i := 0; i < 2; i++ {
|
||
|
val := nodeTest{
|
||
5 years ago
|
data1: correct.ConvertIntToStringface(lib.MultRandWords()),
|
||
|
data2: correct.ConvertIntToStringface(lib.MultRandWords()),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
table = append(table,
|
||
|
nodeTest{
|
||
5 years ago
|
data1: []interface{}{},
|
||
5 years ago
|
data2: []interface{}{"a", 1},
|
||
|
},
|
||
|
)
|
||
|
for _, arg := range table {
|
||
5 years ago
|
for i := 0; i < len(arg.data1); i++ {
|
||
|
listPushBackTest11(link2, link1, arg.data1[i])
|
||
5 years ago
|
}
|
||
|
for i := 0; i < len(arg.data2); i++ {
|
||
|
listPushBackTest11(link2Test, linkTest, arg.data2[i])
|
||
|
}
|
||
|
|
||
5 years ago
|
correct.ListMerge(link1, linkTest)
|
||
5 years ago
|
student.ListMerge(link2, link2Test)
|
||
5 years ago
|
comparFuncList11(link1, link2)
|
||
5 years ago
|
|
||
5 years ago
|
link1 = &List11{}
|
||
5 years ago
|
linkTest = &List11{}
|
||
|
link2 = &ListS11{}
|
||
|
link2Test = &ListS11{}
|
||
|
}
|
||
|
}
|