mirror of https://github.com/01-edu/public.git
Augusto
5 years ago
committed by
xpetit
1 changed files with 113 additions and 123 deletions
@ -1,153 +1,143 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"sort" |
||||
"fmt" |
||||
"strings" |
||||
"testing" |
||||
|
||||
"github.com/01-edu/z01" |
||||
) |
||||
|
||||
func challengeProgram(t *testing.T, stuPath, solPath string, args ...string) { |
||||
exercise := strings.ToLower( |
||||
strings.TrimPrefix(t.Name(), "Test")) |
||||
out, err := z01.MainOut(stuPath+exercise, args...) |
||||
if err != nil { |
||||
t.Error(err) |
||||
} |
||||
correct, err := z01.MainOut(solPath+exercise, args...) |
||||
if err != nil { |
||||
t.Error(err) |
||||
} |
||||
if out != correct { |
||||
t.Errorf("./%s %s prints %q instead of %q\n", |
||||
exercise, strings.Join(args, " "), out, correct) |
||||
} |
||||
} |
||||
|
||||
func TestFlags(t *testing.T) { |
||||
argsAndSolution := map[string]string{ |
||||
"tests/testingSimpleFunc.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-import regexp tests/testingSimpleFunc.go:4:2 |
||||
illegal-call len tests/testingSimpleFunc.go:10:9 |
||||
illegal-access regexp.MustCompile tests/testingSimpleFunc.go:8:8 |
||||
illegal-definition SimpleFunc tests/testingSimpleFunc.go:7:1 |
||||
"tests/alphacount.go": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import regexp tests/alphacount.go:4:2 |
||||
illegal-access regexp.MustCompile tests/alphacount.go:8:8 |
||||
illegal-call len tests/alphacount.go:10:9 |
||||
illegal-call AlphaCount tests/alphacount.go:7:1 |
||||
`, |
||||
|
||||
"-no-for -no-lit=[a-z] tests/printalphabet/printalphabet.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-import fmt tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:6:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:11:7 |
||||
illegal-definition fillArray tests/printalphabet/printalphabet.go:9:1 |
||||
illegal-call int tests/printalphabet/printalphabet.go:17:7 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:21:2 |
||||
illegal-definition main tests/printalphabet/printalphabet.go:15:1 |
||||
illegal-access fmt.Println tests/printalphabet/printalphabet.go:26:3 |
||||
illegal-definition defFun tests/printalphabet/printalphabet.go:25:2 |
||||
illegal-call defFun tests/printalphabet/printalphabet.go:28:2 |
||||
illegal-definition testingScope tests/printalphabet/printalphabet.go:24:1 |
||||
illegal-loop for tests/printalphabet/printalphabet.go:10:2 |
||||
illegal-lit 'a' tests/printalphabet/printalphabet.go:10:11 |
||||
illegal-lit 'z' tests/printalphabet/printalphabet.go:10:21 |
||||
illegal-lit 'a' tests/printalphabet/printalphabet.go:16:14 |
||||
illegal-lit 'b' tests/printalphabet/printalphabet.go:16:19 |
||||
illegal-lit 'c' tests/printalphabet/printalphabet.go:16:24 |
||||
illegal-lit 'd' tests/printalphabet/printalphabet.go:16:29 |
||||
illegal-lit 'e' tests/printalphabet/printalphabet.go:16:34 |
||||
illegal-lit 'f' tests/printalphabet/printalphabet.go:16:39 |
||||
illegal-lit 'a' tests/printalphabet/printalphabet.go:17:11 |
||||
illegal-lit '\n' tests/printalphabet/printalphabet.go:21:16 |
||||
illegal-lit "Hello" tests/printalphabet/printalphabet.go:28:9 |
||||
"-no-for -no-lit=[a-z] tests/printalphabet/printalphabet.go": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:9:7 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:15:2 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:7:1 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:17:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:2 |
||||
illegal-call main tests/printalphabet/printalphabet.go:13:1 |
||||
illegal-literal 'a' tests/printalphabet/printalphabet.go:8:11 |
||||
illegal-literal 'z' tests/printalphabet/printalphabet.go:8:21 |
||||
illegal-literal '\n' tests/printalphabet/printalphabet.go:19:16 |
||||
illegal-literal 'a' tests/printalphabet/printalphabet.go:8:11 |
||||
illegal-literal 'z' tests/printalphabet/printalphabet.go:8:21 |
||||
illegal-literal 'a' tests/printalphabet/printalphabet.go:8:11 |
||||
illegal-literal 'z' tests/printalphabet/printalphabet.go:8:21 |
||||
illegal-loop for tests/printalphabet/printalphabet.go:8:2 |
||||
illegal-loop for tests/printalphabet/printalphabet.go:8:2 |
||||
illegal-loop for tests/printalphabet/printalphabet.go:8:2 |
||||
`, |
||||
"-cast tests/eightqueens.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
"tests/eightqueens.go": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/eightqueens.go:4:2 |
||||
illegal-access z01.PrintRune tests/eightqueens.go:49:5 |
||||
illegal-access z01.PrintRune tests/eightqueens.go:55:2 |
||||
illegal-definition printQueens tests/eightqueens.go:42:1 |
||||
illegal-call rune tests/eightqueens.go:49:19 |
||||
illegal-call printQueens tests/eightqueens.go:70:5 |
||||
illegal-call printQueens tests/eightqueens.go:42:1 |
||||
illegal-call tryX tests/eightqueens.go:73:5 |
||||
illegal-call tryX tests/eightqueens.go:85:2 |
||||
illegal-call tryX tests/eightqueens.go:60:1 |
||||
illegal-call EightQueens tests/eightqueens.go:83:1 |
||||
`, |
||||
"-no-arrays tests/printalphabet/printalphabet.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-import fmt tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:6:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:11:7 |
||||
illegal-definition fillArray tests/printalphabet/printalphabet.go:9:1 |
||||
illegal-call int tests/printalphabet/printalphabet.go:17:7 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:21:2 |
||||
illegal-definition main tests/printalphabet/printalphabet.go:15:1 |
||||
illegal-access fmt.Println tests/printalphabet/printalphabet.go:26:3 |
||||
illegal-definition defFun tests/printalphabet/printalphabet.go:25:2 |
||||
illegal-call defFun tests/printalphabet/printalphabet.go:28:2 |
||||
illegal-definition testingScope tests/printalphabet/printalphabet.go:24:1 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:9:18 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:16:7 |
||||
`, |
||||
"-no-slices tests/printalphabet/printalphabet.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-import fmt tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:6:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:11:7 |
||||
illegal-definition fillArray tests/printalphabet/printalphabet.go:9:1 |
||||
illegal-call int tests/printalphabet/printalphabet.go:17:7 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:21:2 |
||||
illegal-definition main tests/printalphabet/printalphabet.go:15:1 |
||||
illegal-access fmt.Println tests/printalphabet/printalphabet.go:26:3 |
||||
illegal-definition defFun tests/printalphabet/printalphabet.go:25:2 |
||||
illegal-call defFun tests/printalphabet/printalphabet.go:28:2 |
||||
illegal-definition testingScope tests/printalphabet/printalphabet.go:24:1 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:9:18 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:16:7 |
||||
`, |
||||
"-no-these-slices=int,rune tests/printalphabet/printalphabet.go": `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-import fmt tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:6:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:11:7 |
||||
illegal-definition fillArray tests/printalphabet/printalphabet.go:9:1 |
||||
illegal-call int tests/printalphabet/printalphabet.go:17:7 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:21:2 |
||||
illegal-definition main tests/printalphabet/printalphabet.go:15:1 |
||||
illegal-access fmt.Println tests/printalphabet/printalphabet.go:26:3 |
||||
illegal-definition defFun tests/printalphabet/printalphabet.go:25:2 |
||||
illegal-call defFun tests/printalphabet/printalphabet.go:28:2 |
||||
illegal-definition testingScope tests/printalphabet/printalphabet.go:24:1 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:9:18 |
||||
illegal-slice rune tests/printalphabet/printalphabet.go:16:7 |
||||
"-cast tests/eightqueens.go": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/eightqueens.go:4:2 |
||||
illegal-access z01.PrintRune tests/eightqueens.go:49:5 |
||||
illegal-access z01.PrintRune tests/eightqueens.go:55:2 |
||||
`, |
||||
`-allow-builtin tests/doopprog/main.go fmt.Println strconv.Atoi os.Args`: ``, |
||||
`-cast tests/doopprog/main.go fmt.Println strconv.Atoi os.Args len`: ``, |
||||
`tests/testingWrapping.go`: `Cheating: |
||||
TYPE: NAME: LOCATION: |
||||
illegal-call len tests/utilDepth2/wrapper.go:4:9 |
||||
illegal-definition LenWrapper tests/utilDepth2/wrapper.go:3:1 |
||||
illegal-access util2.LenWrapper tests/util/util.go:10:9 |
||||
illegal-definition LenWrapperU tests/util/util.go:9:1 |
||||
illegal-access util.LenWrapperU tests/testingWrapping.go:8:9 |
||||
illegal-definition Length tests/testingWrapping.go:7:1 |
||||
"-no-arrays tests/printalphabet/printalphabet.go ": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:9:7 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:15:2 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:7:1 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:17:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:2 |
||||
illegal-call main tests/printalphabet/printalphabet.go:13:1 |
||||
illegal-array-type rune tests/printalphabet/printalphabet.go:14:8 |
||||
`, |
||||
`tests/testingWrapping.go len`: ``, |
||||
`tests/empty/empty len`: ` No file to analyze |
||||
"-no-these-arrays rune tests/printalphabet/printalphabet.go ": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:9:7 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:15:2 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:7:1 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:17:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:2 |
||||
illegal-call main tests/printalphabet/printalphabet.go:13:1 |
||||
illegal-array-type rune tests/printalphabet/printalphabet.go:14:8 |
||||
`, |
||||
`tests/empty/empty.go tests/empty/empty`: ` tests/empty/empty.go:1:1: expected ';', found 'EOF' (and 2 more errors) |
||||
`-no-these-arrays "int" tests/printalphabet/printalphabet.go`: `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:4:2 |
||||
illegal-call append tests/printalphabet/printalphabet.go:9:7 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:15:2 |
||||
illegal-call fillArray tests/printalphabet/printalphabet.go:7:1 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:17:3 |
||||
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:2 |
||||
illegal-call main tests/printalphabet/printalphabet.go:13:1 |
||||
`, |
||||
} |
||||
|
||||
Compare(t, argsAndSolution) |
||||
} |
||||
|
||||
func Compare(t *testing.T, argsAndSol map[string]string) { |
||||
for args, sol := range argsAndSol { |
||||
a := strings.Split(args, " ") |
||||
out, err := z01.MainOut("../rc", a...) |
||||
if !EqualResult(sol, out) { |
||||
if err == nil { |
||||
out, err := z01.MainOut("../rc", strings.Split(args, " ")...) |
||||
if err.Error() != sol && out != sol { |
||||
fmt.Println("Error:", err) |
||||
fmt.Println("Out:", out) |
||||
t.Errorf("./rc %s prints %q\n instead of %q\n", args, out, sol) |
||||
} |
||||
if err != nil && !EqualResult(sol, err.Error()) { |
||||
t.Errorf("./rc %s prints %q\n instead of %q\n", args, err.Error(), sol) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
func EqualResult(sol, out string) bool { |
||||
// split
|
||||
solSli := strings.Split(sol, "\n") |
||||
outSli := strings.Split(out, "\n") |
||||
// sort
|
||||
sort.Sort(sort.StringSlice(solSli)) |
||||
sort.Sort(sort.StringSlice(outSli)) |
||||
// join
|
||||
sol = strings.Join(solSli, "\n") |
||||
out = strings.Join(outSli, "\n") |
||||
// compare
|
||||
return sol == out |
||||
func TestWrapping(t *testing.T) { |
||||
argsAndSolution := map[string]string{ |
||||
"tests/testingWrapping.go ./util": `Parsing |
||||
OK |
||||
Cheating |
||||
illegal-call len tests/util/util.go:6:9 |
||||
illegal-call util.LenWrapper tests/util/util.go:5:1 |
||||
illegal-call Length tests/testingWrapping.go:7:1 |
||||
`, |
||||
} |
||||
Compare(t, argsAndSolution) |
||||
} |
||||
|
Loading…
Reference in new issue