32 lines
469 B
Go
32 lines
469 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestScanFile(t *testing.T) {
|
|
cases := []struct {
|
|
inFile string;
|
|
want int;
|
|
}{
|
|
{"input1.txt", 142},
|
|
{"input2.txt", 281},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
f, err := os.Open(c.inFile)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := ScanFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if got != c.want {
|
|
t.Errorf("ScanFile(%q) == %d, want %d", c.inFile, got, c.want)
|
|
}
|
|
}
|
|
} |