Dan Anglin
76583b3dda
All checks were successful
/ test (pull_request) Successful in 25s
It's time to add common functions to the internal 'common' package. - Add the function that read the contents from a file to a list. - Add the function that parses a list of integers from a string. ...and more to come later...
33 lines
643 B
Go
33 lines
643 B
Go
package common
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseIntList(t *testing.T) {
|
|
table := []struct {
|
|
list string
|
|
want []int
|
|
}{
|
|
{
|
|
list: "87 2 435 89 100 1 0 16534",
|
|
want: []int{87, 2, 435, 89, 100, 1, 0, 16534},
|
|
},
|
|
{
|
|
list: "145, 834, 66, 2, 90, 123",
|
|
want: []int{145, 834, 66, 2, 90, 123},
|
|
},
|
|
}
|
|
|
|
for i := range table {
|
|
got, err := ParseIntList(table[i].list)
|
|
if err != nil {
|
|
t.Fatalf("received an error after running ParseIntList(); %v", err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, table[i].want) {
|
|
t.Errorf("unexpected result received from ParseIntList(); want %v, got %v", table[i].want, got)
|
|
}
|
|
}
|
|
}
|