-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.go
35 lines (30 loc) · 926 Bytes
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package execute
import (
"fmt"
"os"
)
type TestCases []TestCase
type TestCase struct {
Input string
ExpectedPart1, ExpectedPart2 interface{}
}
func (t TestCases) Run(fn func(string) (interface{}, interface{}), hideInput bool) {
for _, test := range t {
part1I, part2I := fn(test.Input)
part1, expectedPart1, part2, expectedPart2 := fmt.Sprint(part1I), fmt.Sprint(test.ExpectedPart1), fmt.Sprint(part2I), fmt.Sprint(test.ExpectedPart2)
passedPart1 := part1 == expectedPart1 || expectedPart1 == ""
passedPart2 := part2 == expectedPart2 || expectedPart2 == ""
passed := passedPart1 && passedPart2
if !passed && !hideInput {
fmt.Println("Input ", test.Input)
}
if !passedPart1 {
fmt.Println(" - PART1: ", part1, " but expected ", expectedPart1)
os.Exit(1)
}
if !passedPart2 {
fmt.Println(" - PART2: ", part2, " but expected ", expectedPart2)
os.Exit(1)
}
}
}