func TestAdd(t *testing.T) { for _, v := range addTest { ret := mymath.Add(v.a, v.b) if ret != v.ret { t.Errorf("%d add %d, want %d, but get %d", v.a, v.b, v.ret, ret) } } }
func main() { var a, b int = 2, 3 add := mymath.Add(a, b) fmt.Println(add) sub := mymath.Sub(a, b) fmt.Println(sub) mult := mymath.Mult(a, b) fmt.Println(mult) div := mymath.Div(a, b) fmt.Println(div) }
func main() { var personDB map[string]PersonInfo personDB = make(map[string]PersonInfo) // 往这个map里插入几条数据 personDB["12345"] = PersonInfo{"12345", "Tom", "Room 203,..."} personDB["1"] = PersonInfo{"1", "Jack", "Room 101,..."} // 从这个map查找键为"1234"的信息 person, ok := personDB["1234"] delete(personDB, "1234") // ok是一个返回的bool型,返回true表示找到了对应的数据 if ok { fmt.Println("Found person", person.Name, "with ID 1234.") } else { fmt.Println("Did not find person with ID 1234.") } fmt.Println("Found person", example(0)) c, _ := mymath.Add(1, 2) fmt.Println("mymath add", c) test() }
func main() { fmt.Println("Hello World!") fmt.Println(mymath.Add(1, 2)) }