当前位置:网站首页>Go learning --- unit test subtest
Go learning --- unit test subtest
2022-07-01 03:50:00 【Yaya boss】
One 、 Unit test subtest
package subtest
// Define a function
func Add(a,b int) int {
return a + b
}
func Sum(a,b int) int {
return a * b
}
package subtest
import "testing"
// Subtest
func TestSum(t *testing.T) {
t.Run("ping", func(t *testing.T) {
if Sum(2,5) != 10 {
t.Fatal("fail")
}
})
t.Run("dog", func(t *testing.T) {
if Sum(2,-5) != -10 {
t.Fatal("fail")
}
})
}
// Batch subtest
func TestAdd(t *testing.T) {
ces := []struct{
Name string
A int
B int
Fruit int
}{
{"A",1,2,3},
{"B",3,2,5},
{"C",6 ,6,12},
}
for _, ce := range ces {
t.Run(ce.Name, func(t *testing.T) {
ans := Add(ce.A,ce.B)
if ans != ce.Fruit {
t.Fatal(ce.Name,ce.A,ce.B,ce.Fruit)
}
})
}
}
边栏推荐
猜你喜欢

Jeecgboot output log, how to use @slf4j

FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)

MFC window scroll bar usage

AfxMessageBox和MessageBox的用法

Asgnet paper and code interpretation 2

IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍

Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products

谷粒学院微信扫码登录过程记录以及bug解决
![[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
随机推荐
389. 找不同
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
30. 串联所有单词的子串
MFC窗口滚动条用法
MFC window scroll bar usage
4. [WebGIS practice] software operation chapter - data import and processing
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
C语言的sem_t变量类型
214. minimum palindrome string
318. Maximum word length product
166. fractions to decimals
在 C 中声明函数之前调用函数会发生什么?
【TA-霜狼_may-《百人计划》】1.3纹理的秘密
【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
Implement pow (x, n) function
Volley parsing data shows networking failure
You cannot right-click F12 to view the source code solution on the web page
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
241. Design priorities for operational expressions
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)