当前位置:网站首页>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)
}
})
}
}
边栏推荐
- Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
- 205. 同构字符串
- 【TA-霜狼_may-《百人计划》】1.2.1 向量基础
- 389. find a difference
- 431. 将 N 叉树编码为二叉树 DFS
- [TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
- 409. 最长回文串
- 318. Maximum word length product
- Future of NTF and trends in 2022
- Network metering - application layer
猜你喜欢

The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)

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

Valentine's Day is nothing.

Network metering - application layer

Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page

jeecgboot输出日志,@Slf4j的使用方法

不同性能测试工具的并发模式

idea插件备份表

[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API

Jeecgboot output log, how to use @slf4j
随机推荐
Pytorch training deep learning network settings CUDA specified GPU visible
431. 将 N 叉树编码为二叉树 DFS
8. string conversion integer (ATOI)
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
You cannot right-click F12 to view the source code solution on the web page
Cygwin的下载和安装配置
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
All in one 1086: Jiaogu conjecture
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
jeecgboot输出日志,@Slf4j的使用方法
171. Excel 表列序号
What happens when a function is called before it is declared in C?
165. 比较版本号
Leetcode:829. 连续整数求和
Sort linked list (merge sort)
6. zigzag transformation
72. 编辑距离
盘点华为云GaussDB(for Redis)六大秒级能力
409. longest palindrome
Develop industrial Internet with the technical advantages of small programs