예제 #1
0
파일: main.go 프로젝트: cnaize/quiz
func loadWords(path string) (words.WordList, error) {
	var wordList words.WordList

	inFile, err := os.Open(path)
	if err != nil {
		return wordList, err
	}
	defer inFile.Close()

	scanner := bufio.NewScanner(inFile)
	scanner.Split(bufio.ScanLines)
	for scanner.Scan() {
		wordList.AddWord(scanner.Text())
	}

	if err := scanner.Err(); err != nil {
		return wordList, err
	}

	return wordList, nil
}
예제 #2
0
파일: quiz_test.go 프로젝트: cnaize/quiz
func TestQuiz(t *testing.T) {
	var wordList words.WordList
	wordList.AddWord("a")
	wordList.AddWord("b")
	wordList.AddWord("c")
	wordList.AddWord("df")
	wordList.AddWord("bdfc")
	wordList.AddWord("acdfe")

	res := words.HandleWord("df", wordList).(words.Result)
	if len(res) != 0 {
		t.Errorf("failed: df")
	}

	res = words.HandleWord("acdfe", wordList).(words.Result)
	if len(res) != 0 {
		t.Errorf("failed: acdfe")
	}

	res = words.HandleWord("bdfc", wordList).(words.Result)
	if len(res) != 1 || res[0] != "bdfc" {
		t.Errorf("failed: bdfc")
	}
}