開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 14(code quality assurance - Automated Testing)、Code Magnets(416)の解答を求めてみる。
コード
larger_test.go
package compare import ( "fmt" "testing" ) func TestFirstLarger(t *testing.T) { want := 2 got := Larger(2, 1) if got != want { t.Errorf(errorString(2, 1, got, want)) } } func TestSecondLarger(t *testing.T) { want := 8 got := Larger(4, 8) if got != want { t.Errorf(errorString(4, 8, got, want)) } } func errorString(a, b, got, want int) string { return fmt.Sprintf("Larger(%d, %d) = %d, want %d", a, b, got, want) }
larger.go
package compare func Larger(a, b int) int { if a < b { return a } return b }
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go test --- FAIL: TestFirstLarger (0.00s) larger_test.go:12: Larger(2, 1) = 1, want 2 --- FAIL: TestSecondLarger (0.00s) larger_test.go:20: Larger(4, 8) = 4, want 8 FAIL exit status 1 FAIL headfirstgo/compare 0.005s $
0 コメント:
コメントを投稿