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.
69 lines
1.6 KiB
69 lines
1.6 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"strconv"
|
||
5 years ago
|
|
||
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 (
|
||
|
ListS = correct.List
|
||
|
List = student.List
|
||
|
)
|
||
5 years ago
|
|
||
|
func listToStringStu10(l *List) 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
|
||
|
}
|
||
|
|
||
|
// makes the test, compares 2 lists one from the solutions and the other from the student
|
||
5 years ago
|
func comparFuncList(l *ListS, l1 *List, data []interface{}) {
|
||
5 years ago
|
for l.Head != nil || l1.Head != nil {
|
||
|
if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) {
|
||
5 years ago
|
lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu10(l1), correct.ListToString(l.Head), l1.Head, l.Head)
|
||
5 years ago
|
}
|
||
|
if l.Head.Data != l1.Head.Data {
|
||
5 years ago
|
lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu10(l1), correct.ListToString(l.Head), l1.Head.Data, l.Head.Data)
|
||
5 years ago
|
}
|
||
|
l.Head = l.Head.Next
|
||
|
l1.Head = l1.Head.Next
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
|
link1 := &ListS{}
|
||
5 years ago
|
link2 := &List{}
|
||
|
|
||
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{}{"Hello", "man", "how are you"},
|
||
|
},
|
||
|
)
|
||
|
for _, arg := range table {
|
||
5 years ago
|
for _, item := range arg.Data {
|
||
|
student.ListPushBack(link2, item)
|
||
5 years ago
|
correct.ListPushBack(link1, item)
|
||
5 years ago
|
}
|
||
5 years ago
|
comparFuncList(link1, link2, arg.Data)
|
||
5 years ago
|
}
|
||
|
}
|