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.
67 lines
1.6 KiB
67 lines
1.6 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"strconv"
|
||
5 years ago
|
|
||
5 years ago
|
"../lib"
|
||
|
"./correct"
|
||
|
"./student"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
type ListSa = correct.List
|
||
5 years ago
|
type Lista = student.List
|
||
|
|
||
|
func listToStringStu11(l *Lista) 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
|
// makes the test, compares 2 lists one from the solutions and the other from the student
|
||
|
func comparFuncList1(l *Lista, l1 *ListSa, 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\nListPushFront()== %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu11(l), correct.ListToString(l1.Head), l.Head, l1.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\nListPushFront()== %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu11(l), correct.ListToString(l1.Head), l.Head, l1.Head)
|
||
5 years ago
|
}
|
||
|
l1.Head = l1.Head.Next
|
||
|
l.Head = l.Head.Next
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
// to insert a value in the first position of the list
|
||
|
func main() {
|
||
|
link1 := &Lista{}
|
||
5 years ago
|
link2 := &ListSa{}
|
||
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.ListPushFront(link1, item)
|
||
5 years ago
|
correct.ListPushFront(link2, item)
|
||
5 years ago
|
}
|
||
5 years ago
|
comparFuncList1(link1, link2, arg.Data)
|
||
|
link1 = &Lista{}
|
||
5 years ago
|
link2 = &ListSa{}
|
||
|
}
|
||
|
}
|