Kadai3-1: nagaa052 - #25
Open
nagaa052 wants to merge 4 commits into
Open
Conversation
tenntenn
reviewed
Jun 21, 2019
| flag.Usage = usage | ||
| flag.Parse() | ||
|
|
||
| g, err := game.New(game.Options{ |
tenntenn
reviewed
Jun 21, 2019
| }, os.Stdin, os.Stdout, os.Stderr) | ||
|
|
||
| if err != nil { | ||
| log.Fatal("Failed to start the game") |
tenntenn
reviewed
Jun 21, 2019
| ) | ||
|
|
||
| const ( | ||
| ExitOK = iota |
Member
There was a problem hiding this comment.
プログラムの外部に出る情報にはiotaを使わない。
例:DBに保存されるもの、ネットワークを介して送られるもの、コマンドライツールの出力になるもの
tenntenn
reviewed
Jun 21, 2019
| // Game is manages game information | ||
| type Game struct { | ||
| qs *questions.Questions | ||
| *Result |
tenntenn
reviewed
Jun 21, 2019
| // DefaultOptions is the default value of Options. | ||
| var DefaultOptions = Options{ | ||
| TimeUpSecond: 30, | ||
| IsColor: false, |
tenntenn
reviewed
Jun 21, 2019
| // Options is a specifiable option. | ||
| type Options struct { | ||
| TimeUpSecond int | ||
| IsColor bool |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| // Options is a specifiable option. | ||
| type Options struct { | ||
| TimeUpSecond int |
tenntenn
reviewed
Jun 21, 2019
| } | ||
|
|
||
| // Print is Output the result. | ||
| func (r *Result) Print(out io.Writer) { |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| return &Game{ | ||
| qs: qs, | ||
| Result: &Result{}, |
Member
There was a problem hiding this comment.
埋め込むならポインタじゃなくてもいい。そしたらゼロ値で使える。
tenntenn
reviewed
Jun 21, 2019
| scanner := bufio.NewScanner(g.inStream) | ||
| defer close(dst) | ||
|
|
||
| for scanner.Scan() { |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| func (g *Game) getQuestion() (*questions.Question, error) { | ||
|
|
||
| rand.Seed(time.Now().UnixNano()) |
tenntenn
reviewed
Jun 21, 2019
| func (g *Game) getQuestion() (*questions.Question, error) { | ||
|
|
||
| rand.Seed(time.Now().UnixNano()) | ||
| index := rand.Intn(g.qs.GetSize()) |
tenntenn
reviewed
Jun 21, 2019
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { |
tenntenn
reviewed
Jun 21, 2019
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| inStream := &bytes.Buffer{} |
tenntenn
reviewed
Jun 21, 2019
| _, err := game.New(tt.opt, inStream, outStream, errStream) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr) | ||
| return |
tenntenn
reviewed
Jun 21, 2019
| got, err := game.ExportGetQuestion(g) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("Game.getQuestion() error = %v, wantErr %v", err, tt.wantErr) | ||
| return |
tenntenn
reviewed
Jun 21, 2019
|
|
||
| type inMemQ struct{} | ||
|
|
||
| var words = []string{ |
tenntenn
reviewed
Jun 21, 2019
| want *qs.Questions | ||
| wantErr bool | ||
| }{ | ||
| { |
tenntenn
reviewed
Jun 21, 2019
| want bool | ||
| }{ | ||
| { | ||
| name: "Is correct test", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
タイピングゲーム
要件
コマンド/オプション
パッケージ構成
main: 起動/コマンドオプションpkg/game: タイピングゲームのメインロジックpkg/questions: 問題の管理/取得やってみたこと
できなかったこと