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

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 
} 
主站蜘蛛池模板: 平邑县| 东台市| 鞍山市| 宜黄县| 舟山市| 陆河县| 手游| 夹江县| 许昌县| 奈曼旗| 塔城市| 四平市| 武城县| 达孜县| 许昌市| 岳西县| 渑池县| 门头沟区| 英吉沙县| 公安县| 双鸭山市| 西乌珠穆沁旗| 习水县| 闻喜县| 邹城市| 儋州市| 南澳县| 崇信县| 古田县| 碌曲县| 盱眙县| 祥云县| 都匀市| 汕头市| 平邑县| 白山市| 观塘区| 临高县| 高阳县| 门源| 双峰县|