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

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 
} 
主站蜘蛛池模板: 株洲市| 曲阜市| 西盟| 虞城县| 凌云县| 遂川县| 陵川县| 天峻县| 百色市| 无极县| 浮山县| 三江| 陈巴尔虎旗| 永新县| 阜宁县| 曲麻莱县| 巢湖市| 承德市| 潮安县| 昔阳县| 泌阳县| 汶川县| 长子县| 玉田县| 图们市| 双牌县| 哈巴河县| 柘荣县| 云阳县| 收藏| 恩施市| 乌鲁木齐县| 乌兰浩特市| 自贡市| 聂拉木县| 铁力市| 江安县| 临湘市| 马龙县| 临沧市| 成都市|