Playing with test framework
This commit is contained in:
parent
302e593f0f
commit
d5909ca148
2 changed files with 67 additions and 32 deletions
11
11/11.go
11
11/11.go
|
@ -13,9 +13,13 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
s := strings.Split(scanner.Text(), ",")
|
s := strings.Split(scanner.Text(), ",")
|
||||||
|
fmt.Println(CalcDistance(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CalcDistance(s []string) []int {
|
||||||
|
|
||||||
x := 0
|
x := 0
|
||||||
ne := 0
|
ne := 0
|
||||||
|
@ -50,9 +54,10 @@ func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(getDistance(x, ne), max)
|
cd := getDistance(x, ne)
|
||||||
|
|
||||||
|
return []int{cd, max}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDistance(x int, ne int) int {
|
func getDistance(x int, ne int) int {
|
||||||
|
|
30
11/11_test.go
Normal file
30
11/11_test.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testpair struct {
|
||||||
|
values []string
|
||||||
|
result int
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = []testpair{
|
||||||
|
{[]string{"ne","ne","ne"}, 3},
|
||||||
|
{[]string{"ne","ne","sw","sw"}, 0},
|
||||||
|
{[]string{"ne","ne","s","s"}, 2},
|
||||||
|
{[]string{"se","sw","se","sw","sw"}, 3},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCalcDistance(t *testing.T) {
|
||||||
|
for _, pair := range tests {
|
||||||
|
v := CalcDistance(pair.values)
|
||||||
|
if v[0] != pair.result {
|
||||||
|
t.Error(
|
||||||
|
"For", pair.values,
|
||||||
|
"expected", pair.result,
|
||||||
|
"got", v[0],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue