開発環境
- 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)、Exercise(409)の解答を求めてみる。
コード
math_test.go
package arithmetic
import "testing"
func TestAdd(t *testing.T) {
 if Add(1, 2) != 3 {
  t.Errorf("1 + 2 did not equal 3")
 }
}
func TestSub(t *testing.T) {
 if Sub(8, 4) != 4 {
  t.Errorf("8 - 4 did not equal 4")
 }
}
math.go
package arithmetic
func Add(a, b float64) float64 {
 return a + b
}
func Sub(a, b float64) float64 {
 return a - b
}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go test # _/.../go/Head_First_Go/ch14/arithmetic [_/.../go/Head_First_Go/ch14/arithmetic.test] ./math_test.go:6:5: undefined: Add FAIL _/.../go/Head_First_Go/ch14/arithmetic [build failed] $ go test PASS ok _/.../go/Head_First_Go/ch14/arithmetic 0.005s $ go test # _/.../go/Head_First_Go/ch14/arithmetic [_/.../go/Head_First_Go/ch14/arithmetic.test] ./math_test.go:12:5: undefined: Sub FAIL _/.../go/Head_First_Go/ch14/arithmetic [build failed] $ go test PASS ok _/.../go/Head_First_Go/ch14/arithmetic 0.005s $
 
0 コメント:
コメントを投稿