39 lines
972 B
Go
39 lines
972 B
Go
package judge
|
|
|
|
import "fmt"
|
|
|
|
type QueryResult struct {
|
|
Columns []string
|
|
Rows [][]any
|
|
}
|
|
|
|
type Verdict struct {
|
|
Pass bool
|
|
Hint string
|
|
}
|
|
|
|
func Compare(expected QueryResult, actual QueryResult) Verdict {
|
|
if len(expected.Columns) != len(actual.Columns) {
|
|
return Verdict{Pass: false, Hint: "列数量不一致"}
|
|
}
|
|
for i := range expected.Columns {
|
|
if expected.Columns[i] != actual.Columns[i] {
|
|
return Verdict{Pass: false, Hint: "列顺序或列名不一致"}
|
|
}
|
|
}
|
|
if len(expected.Rows) != len(actual.Rows) {
|
|
return Verdict{Pass: false, Hint: "返回行数不一致"}
|
|
}
|
|
for r := range expected.Rows {
|
|
if len(expected.Rows[r]) != len(actual.Rows[r]) {
|
|
return Verdict{Pass: false, Hint: "返回列数不一致"}
|
|
}
|
|
for c := range expected.Rows[r] {
|
|
if fmt.Sprint(expected.Rows[r][c]) != fmt.Sprint(actual.Rows[r][c]) {
|
|
return Verdict{Pass: false, Hint: "结果内容不一致"}
|
|
}
|
|
}
|
|
}
|
|
return Verdict{Pass: true, Hint: "结果正确"}
|
|
}
|