Ai
1 Star 0 Fork 0

ghosind/utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cond_test.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
ghosind 提交于 2023-08-22 21:35 +08:00 . feat: add MaxN and MinN.
package utils
import (
"testing"
"github.com/ghosind/go-assert"
)
func TestConditional(t *testing.T) {
a := assert.New(t)
language := "fr"
ret := Conditional(language == "en", "Hello", "Bonjour")
a.EqualNow(ret, "Bonjour")
}
func TestConditionalExpr(t *testing.T) {
a := assert.New(t)
var str *string
ret := ConditionalExpr(
str != nil,
func() string {
return *str
},
func() string {
return ""
},
)
a.Equal(ret, "")
str = Pointer("Hello world")
ret = ConditionalExpr(
str != nil,
func() string {
return *str
},
func() string {
return ""
},
)
a.Equal(ret, "Hello world")
}
func TestMax(t *testing.T) {
assertion := assert.New(t)
a := 1
b := 2
max := Max(a, b)
assertion.Equal(max, b)
}
func TestMaxN(t *testing.T) {
assertion := assert.New(t)
assertion.Equal(MaxN[int](), 0)
assertion.Equal(MaxN(2, 1, 1), 2)
assertion.Equal(MaxN(-1, 1, -1), 1)
assertion.Equal(MaxN(1, 2, 3, 4, 3, 2, 1), 4)
}
func TestMin(t *testing.T) {
assertion := assert.New(t)
a := 1
b := 2
min := Min(a, b)
assertion.Equal(min, a)
}
func TestMinN(t *testing.T) {
assertion := assert.New(t)
assertion.Equal(MinN[int](), 0)
assertion.Equal(MinN(2, 1, 2), 1)
assertion.Equal(MinN(-1, 1, -1), -1)
assertion.Equal(MinN(4, 3, 2, 1, 2, 3, 4), 1)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ghosind/utils.git
git@gitee.com:ghosind/utils.git
ghosind
utils
utils
main

搜索帮助