開発環境
- 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 8(building storage - Structs)、Pool Puzzle(252)の解答を求めてみる。
コード
sample4_test.go
package main
import (
"headfirstgo/geo"
"testing"
)
func TestPublicStruct(t *testing.T) {
location := geo.Coordinates{Latitude: 37.42, Longitude: -122.08}
wants := []float64{37.42, -122.08}
gots := []float64{location.Latitude, location.Longitude}
s := []string{"Latitude", "Longitude"}
for i, got := range gots {
want := wants[i]
if got != want {
t.Errorf("%s = got %f, want %f", s[i], got, want)
}
}
}
sample4.go
package main
func main() {}
~~/go/src/headfirstgo/geo/geo.go
package geo
type Coordinates struct {
Latitude float64
Longitude float64
}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go test PASS ok _/.../go/Head_First_Go/ch8/sample4 0.005s $
0 コメント:
コメントを投稿