開発環境
- 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 1(let's get going - Syntax Basics)、Exercise(15)の解答を求めてみる。
コード
sample2_test.go
package main
import (
"reflect"
"testing"
)
func TestTypes(t *testing.T) {
wants := []string{
"int",
"bool",
"float64",
"int",
"bool",
"float64",
"string",
}
gots := []reflect.Type{
reflect.TypeOf(25),
reflect.TypeOf(true),
reflect.TypeOf(5.2),
reflect.TypeOf(1),
reflect.TypeOf(false),
reflect.TypeOf(1.0),
reflect.TypeOf("hello"),
}
for i, want := range wants {
got := gots[i].String()
if got != want {
t.Errorf("%v != %v\n", got, want)
}
}
}
sample2.go
package main
func main() {}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go test PASS ok .../go/Head_First_Go/ch1/sample2 0.005s $
0 コメント:
コメントを投稿