Skip to content

kadai3-1-pei #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

kadai3-1-pei #27

wants to merge 10 commits into from

Conversation

suaaa7
Copy link

@suaaa7 suaaa7 commented Aug 6, 2019

課題3-1 タイピングゲームを作ろう

  • 標準出力に英単語を出す(出すものは自由)
  • 標準入力から1行受け取る
  • 制限時間内に何問解けたか表示する
  • 制限時間にはtime.After関数を用いる
    • context.WithTimeoutでもよい
  • select構文を用いる
    • 制限時間と入力を同時に待つ

TODO

  • READMEの追加
  • テスト書けていない部分を書く
    • mainのテスト
    • typingのテスト
  • オプションで制限時間を変更できるようにする

@suaaa7 suaaa7 self-assigned this Aug 6, 2019
@suaaa7 suaaa7 added the kadai3-1 label Aug 6, 2019
wr := &wordsreader.WordsReader{FileName: "./textdata/words.txt"}
words, err := wr.Read()
if err != nil {
return ExitCodeError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これだとどういうエラーが起きたのか分からないのでは?

typingCh := typing.Question(words)
timerCh := time.After(5 * time.Second)

counter := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ゼロ値でよい

fmt.Println("End Typing Game!")
return ExitCodeOK
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returnなくて動きます?

word := words[rand.Intn(len(words))]
fmt.Println(word)

stdin.Scan()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラー処理は?

defer fp.Close()

scanner := bufio.NewScanner(fp)
for scanner.Scan() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラー処理


// Read file
func (wr WordsReader) Read() ([]string, error) {
words := make([]string, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var words []string で十分

t.Run(c.fileName, func(t *testing.T) {
t.Parallel()
wr := WordsReader{FileName: c.fileName}
if actual, _ := wr.Read(); !reflect.DeepEqual(c.expected, actual) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストであってもエラー処理を省かない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants