開発環境
- 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 6(appending issue - Slice)、Exercise(191)の解答を求めてみる。
コード
sample2_test.go
package main import "testing" func TestSlice(t *testing.T) { array := [5]string{"a", "b", "c", "d", "e"} slice := array[1:3] slice = append(slice, "x") slice = append(slice, "y", "z") wants := []string{"b", "c", "x", "y", "z"} for i, got := range slice { want := wants[i] if got != want { t.Errorf("slice[%d] = %s, want %s", i, got, want) } } }
sample2.go
package main func main() {}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go test PASS ok _/.../Head_First_Go/ch6/sample2 0.005s $
0 コメント:
コメントを投稿