2019年7月25日木曜日

開発環境

Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 7(labeling data - Maps)、Exercise(214)の解答を求めてみる。

コード

sample1_test.go

package main

import "testing"

func TestMapJewelry(t *testing.T) {
 jewelry := make(map[string]float64)
 jewelry["necklace"] = 89.99
 jewelry["earrings"] = 79.99
 wants := []float64{79.99, 89.99}
 js := []string{"earrings", "necklace"}
 for i, j := range js {
  want := wants[i]
  got := jewelry[j]
  if got != want {
   t.Errorf("jewelry[%s] = %f, want %f", j, got, want)
  }
 }
}
func TestMapClothing(t *testing.T) {
 clothing := map[string]float64{"pants": 59.99, "shirt": 39.99}
 cs := []string{"shirt", "pants"}
 wants := []float64{39.99, 59.99}
 for i, c := range cs {
  want := wants[i]
  got := clothing[c]
  if got != want {
   t.Errorf("clothing[%s] = %f, want %f", c, got, want)
  }
 }
}

sample1.go

package main

func main() {}

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

$ go test
PASS
ok   _/.../go/Head_First_Go/ch7/sample1 0.004s
$ 

0 コメント:

コメントを投稿