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

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 
} 
主站蜘蛛池模板: 平江县| 呼伦贝尔市| 河津市| 雅安市| 山西省| 水城县| 巴彦县| 政和县| 敦煌市| 苏尼特左旗| 尼玛县| 永登县| 肃宁县| 潞城市| 鞍山市| 三原县| 安多县| 马关县| 道真| 宜兴市| 兴海县| 屯门区| 渝北区| 青浦区| 镇原县| 衡东县| 安图县| 新竹县| 诏安县| 称多县| 娱乐| 梧州市| 慈溪市| 布拖县| 昌平区| 新郑市| 大厂| 宁国市| 花莲市| 响水县| 恩施市|