Open
Conversation
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.
2回目の宿題を提出します。よろしくお願いします。
io.Readerとio.Writerについて調べてみよう
標準パッケージでどのように使われているか
様々な入出力を扱う抽象としてio.Reader,ioWriterのinterfaceが定義されている。
io.Readerを実装した標準パッケージの構造体としては、例えばos.File(ファイルの読み込み),os.Stdin(標準入力),bytes.Buffer(メモリに蓄えた内容の読み込み),net.conn(ネットワーク通信からの読み込み)が挙げられる。
また、io.Writerを実装した標準パッケージの構造体としては、例えばos.File(ファイルの書き込み),os.Stdout(標準出力),bytes.Buffer(メモリへの書き込み),net.conn(ネットワーク通信への送信)が挙げられる。
io.Readerとio.Writerがあることでどういう利点があるのか具体例を挙げて考えてみる
入力元や出力先に関して、ファイルなのか、標準入力出力なのか、メモリなのか、ネットワーク通信なのか、etc...等様々あるが、それらの切り替えを簡単に行うことができる。
具体例としては、結果を標準出力に表示していたプログラムをファイル書き出しに仕様変更するときに、os.Stdoutを使用していた箇所をos.Fileに変更する改修を行うというだけ(大枠としては。細かいところでは他にも実装が必要そうな気がする。)で済む。
1回目の宿題のテストを作ってみて下さい
テストのしやすさを考えてリファクタリングしてみる
SearcherとConverterにInterfaceを用意し、テストでダミー実装を差し込めるようにした
2d9f969
テストのカバレッジを取ってみる
go test -coverprofile=profile github.com/gopherdojo/dojo2/kadai2/kadai2-2/imageconverterで出力。go tool cover -html=profileでブラウザ上で閲覧。043c3e7
テーブル駆動テストを行う
CommandValidatorおよびFormatのテストにて実装。
56dccc5
テストヘルパーを作ってみる
Converterのテストにて実装。
0c9f8cb