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.
55 lines
1.4 KiB
55 lines
1.4 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"os/exec"
|
||
5 years ago
|
"strconv"
|
||
|
|
||
4 years ago
|
"github.com/01-edu/public/go/tests/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()
|
||
4 years ago
|
if _, ok := err.(*exec.ExitError); ok {
|
||
|
lib.Fatalf("%s\n", b)
|
||
|
} else {
|
||
|
lib.Fatalf("%s\n", err)
|
||
5 years ago
|
}
|
||
4 years ago
|
return string(b)
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
// executes the test and compares student with solutions
|
||
4 years ago
|
executeTest := func(name string, x, y int) {
|
||
5 years ago
|
var output, correct string
|
||
5 years ago
|
|
||
5 years ago
|
if x == 0 && y == 0 {
|
||
4 years ago
|
output = execFatal("sh", "-c", name+" | ./raid3")
|
||
|
correct = execFatal("sh", "-c", name+" | raid3_prog")
|
||
5 years ago
|
} else {
|
||
4 years ago
|
output = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3")
|
||
|
correct = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | raid3_prog")
|
||
5 years ago
|
}
|
||
5 years ago
|
if output != correct {
|
||
5 years ago
|
lib.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n",
|
||
4 years ago
|
name, x, y, output, correct)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// testing all raids1
|
||
4 years ago
|
names := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"}
|
||
|
for _, name := range names {
|
||
5 years ago
|
x := lib.RandIntBetween(1, 50)
|
||
|
y := lib.RandIntBetween(1, 50)
|
||
4 years ago
|
executeTest(name, 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
|
}
|