Getting sidetracked writing utility functions

This commit is contained in:
Dan Buch 2012-11-18 13:47:26 -05:00
parent 8ca6f624d4
commit 869142a314
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package algs4
import (
"bufio"
"io"
"strconv"
)
func ReadInts(infile io.Reader) ([]int64, error) {
ints := make([]int64, 0)
var i int64
fileReader := bufio.NewReader(infile)
line, err := fileReader.ReadString('\n')
for err == nil {
i, err = strconv.ParseInt(line, 10, 0)
if err != nil {
return nil, err
}
ints = append(ints, i)
line, err = fileReader.ReadString('\n')
}
return ints, nil
}

View File

@ -0,0 +1,11 @@
package algs4_test
import (
"testing"
)
func TestReadInts(t *testing.T) {
if 1 == 0 {
t.Error("WAT")
}
}