2019年8月3日土曜日

開発環境

Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 9(you're my type - Defined Types)、Pool Puzzle(270)の解答を求めてみる。

コード

sample1_test.go

package main

import (
 "fmt"
 "testing"
)

func TestType(t *testing.T) {
 population := Population(572)
 want := "Sleepy Creek Country population: 572"
 got := fmt.Sprintf("Sleepy Creek Country population: %v", population)
 if got != want {
  t.Errorf("got %v, want %v", got, want)
 }
 population += 1
 if population != 573 {
  t.Errorf("got %v, want %v", population, 573)
 }
}

sample1.go

package main

type Population int

func main() {}

入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)

$ go test
# _/.../go/Head_First_Go/ch9/sample1 [_/.../go/Head_First_Go/ch9/sample1.test]
./sample1_test.go:9:16: undefined: Population
FAIL _/.../go/Head_First_Go/ch9/sample1 [build failed]
$ go test
PASS
ok   _/.../go/Head_First_Go/ch9/sample1 0.004s
$ 

0 コメント:

コメントを投稿