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.
65 lines
1.8 KiB
65 lines
1.8 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"os/exec"
|
||
5 years ago
|
"strconv"
|
||
|
|
||
5 years ago
|
"../lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
execFatal := func(name string, arg ...string) string {
|
||
|
b, err := exec.Command(name, arg...).CombinedOutput()
|
||
|
s := string(b)
|
||
|
if err != nil {
|
||
5 years ago
|
lib.Fatal(s)
|
||
5 years ago
|
}
|
||
5 years ago
|
return s
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
// executes the test and compares student with solutions
|
||
|
executeTest := func(args string, x, y int) {
|
||
|
var output, correct string
|
||
5 years ago
|
|
||
5 years ago
|
if x == 0 && y == 0 {
|
||
|
output = execFatal("sh", "-c", args+" | ./raid3_student")
|
||
|
correct = execFatal("sh", "-c", args+" | ./raid3")
|
||
|
} else {
|
||
|
output = execFatal("sh", "-c", "./"+args+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3_student")
|
||
|
correct = execFatal("sh", "-c", "./"+args+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3")
|
||
5 years ago
|
}
|
||
5 years ago
|
if output != correct {
|
||
5 years ago
|
lib.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n",
|
||
5 years ago
|
args, x, y, output, correct)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
// builds all the files for testing, student, solution and relevant files
|
||
|
execFatal("go", "build", "-o", "raid3", "solutions/raid3/main.go")
|
||
|
execFatal("go", "build", "-o", "raid3_student", "student/raid3/main.go")
|
||
5 years ago
|
execFatal("go", "build", "solutions/raid3/raid1aprog/raid1a.go")
|
||
|
execFatal("go", "build", "solutions/raid3/raid1bprog/raid1b.go")
|
||
|
execFatal("go", "build", "solutions/raid3/raid1cprog/raid1c.go")
|
||
|
execFatal("go", "build", "solutions/raid3/raid1dprog/raid1d.go")
|
||
|
execFatal("go", "build", "solutions/raid3/raid1eprog/raid1e.go")
|
||
5 years ago
|
|
||
5 years ago
|
// testing all raids1
|
||
5 years ago
|
table := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"}
|
||
5 years ago
|
for _, s := range table {
|
||
5 years ago
|
x := lib.RandIntBetween(1, 50)
|
||
|
y := lib.RandIntBetween(1, 50)
|
||
5 years ago
|
executeTest(s, x, y)
|
||
5 years ago
|
}
|
||
|
|
||
|
// testing special case AA, AC, A, A
|
||
5 years ago
|
// A C
|
||
5 years ago
|
executeTest("raid1e", 2, 1)
|
||
|
executeTest("raid1c", 2, 1)
|
||
|
executeTest("raid1d", 1, 2)
|
||
|
executeTest("raid1e", 1, 2)
|
||
|
executeTest("raid1e", 1, 1)
|
||
|
executeTest("echo", 0, 0)
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
|
// TODO: fix paths
|