-
Notifications
You must be signed in to change notification settings - Fork 29
/
random_test.go
46 lines (37 loc) · 1 KB
/
random_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package namegen
import (
"testing"
"github.com/go-playground/assert"
)
func Test_RandomItem(t *testing.T) {
result, err := RandomItem([]string{})
assert.NotEqual(t, nil, err)
assert.Equal(t, 0, len(result))
generator := NameGeneratorFromType(origins[0], genders[0])
result, err = RandomItem(generator.FemaleFirstNames)
assert.Equal(t, nil, err)
assert.NotEqual(t, 0, len(result))
}
func Test_RandomItemFromThresholdMap(t *testing.T) {
genderTreshold := map[string]int{}
for i, gender := range genders {
genderTreshold[gender] = i
}
result := RandomItemFromThresholdMap(genderTreshold)
assert.NotEqual(t, "", result)
}
func Test_RandomItemInCollection(t *testing.T) {
for _, origin := range origins {
ok := RandomItemInCollection(origin, origins)
assert.Equal(t, true, ok)
}
ok := RandomItemInCollection("none", origins)
assert.Equal(t, false, ok)
}
func Test_RandomSeedFromString(t *testing.T) {
defer func() {
err := recover()
assert.Equal(t, nil, err)
}()
RandomSeedFromString("none")
}