1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package FileList type FileList struct { lists []string } func NewList() *FileList { c := new(FileList) c.lists = make([]string, 0) return c } func (c *FileList) Add(s string) { c.lists = append(c.lists, s) } func (c *FileList) GetAll() []string { return c.lists } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
package FileList import ( "log" "testing" ) //TestXXXとする func TestA(t *testing.T) { fileList := NewList() fileList.Add("鉛筆") fileList.Add("ボールペン") f := fileList.GetAll() if len(f) != 2 { t.Fatalf("length error %d", len(f)) //Fatalは失敗時テスト終了 } if f[1] != "鉛筆" { t.Error("鉛筆なし") t.Log(f) } log.Print("done") } |