1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

feat: add RandFromGivenSlice function (#235)

* feat: add RandFromGivenSlice function

* feat: add RandFromGivenSlice function
This commit is contained in:
残念
2024-08-14 19:36:12 +08:00
committed by GitHub
parent a360372aa9
commit 7b4e060f85
5 changed files with 105 additions and 0 deletions

View File

@@ -269,6 +269,29 @@ func TestRandStringSlice(t *testing.T) {
// })
}
func TestRandFromGivenSlice(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestRandFromGivenSlice")
randomSet := []any{"a", 8, "王", true, 1.1}
result := RandFromGivenSlice(randomSet)
find := false
for _, v := range randomSet {
if v == result {
find = true
}
}
assert.Equal(true, find)
emptyAnyRandomSet := []any{}
emptyAnyResult := RandFromGivenSlice(emptyAnyRandomSet)
assert.IsNil(emptyAnyResult)
emptyIntRandomSet := []int{}
emtpyIntResult := RandFromGivenSlice(emptyIntRandomSet)
assert.Equal(0, emtpyIntResult)
}
func TestRandBool(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestRandBool")