-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadworddict_test.go
44 lines (36 loc) · 928 Bytes
/
loadworddict_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
36
37
38
39
40
41
42
43
44
package wordladder
import (
"bufio"
"errors"
"strings"
"testing"
)
func TestLoadWordDict(t *testing.T) {
const input = "one two three four five"
scanner := bufio.NewScanner(strings.NewReader(input))
scanner.Split(bufio.ScanWords)
var dict WordSet
var err error
if dict, err = LoadWordDict(scanner); err != nil {
t.Fatalf("error loading dictionary: %v", err)
}
if len(dict) != 5 {
t.Fatal("unexpected number of words in dictionary")
}
}
type badReader struct {
}
func (r *badReader) Read(p []byte) (n int, err error) {
return 0, errors.New("bad reader")
}
func TestLoadWordDictBadReader(t *testing.T) {
scanner := bufio.NewScanner(&badReader{})
if _, err := LoadWordDict(scanner); err == nil {
t.Fatalf("expected error loading dictionary with bad reader")
}
}
func TestLoadWordDictNilScanner(t *testing.T) {
if _, err := LoadWordDict(nil); err == nil {
t.Fatal("no error with nil scanner")
}
}