官术网_书友最值得收藏!

addInt.go

The tests in variadic_test.go elaborated on the rules for the variadic function. However, you might have noticed that TestSimpleVariadicToSlice ran three tests in its function body, but go test treats it as a single test. Go provides a good way to run multiple tests within a single function, and we shall look them in addInt_test.go.

For this example, we will use a very simple function as shown in this code:

// addInt.go 
 
package main 
 
func addInt(numbers ...int) int { 
    sum := 0 
    for _, num := range numbers { 
        sum += num 
    } 
    return sum 
} 
主站蜘蛛池模板: 丰城市| 大田县| 永清县| 乌兰浩特市| 石柱| 柘城县| 北辰区| 神池县| 邢台市| 钟山县| 金门县| 江都市| 香港 | 涟源市| 林口县| 开远市| 宁河县| 扶沟县| 孟连| 璧山县| 建德市| 迁西县| 南靖县| 铁岭市| 营口市| 泰来县| 林甸县| 汕尾市| 高平市| 阿拉善盟| 安仁县| 德令哈市| 鄢陵县| 岚皋县| 龙口市| 敦化市| 汉沽区| 越西县| 射洪县| 镇沅| 巴林右旗|