-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathrandom_element_test.go
49 lines (41 loc) · 1005 Bytes
/
random_element_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
47
48
49
package faker
import "testing"
func TestRandomElement(t *testing.T) {
f := New()
m := []string{"str1", "str2"}
randomStr := RandomElement(f, m...)
Expect(t, true, randomStr == "str1" || randomStr == "str2")
}
func TestRandomElementWeighted(t *testing.T) {
f := New()
m := map[int]string{
0: "zeroChance",
1: "someChance",
5: "moreChance",
}
for i := 0; i < 5; i++ {
got := RandomElementWeighted(f, m)
Expect(t, true, got == "someChance" || got == "moreChance")
Expect(t, true, got != "zeroChance")
}
}
func TestRandomMapKey(t *testing.T) {
f := New()
m := map[int]string{
1: "one",
5: "five",
42: "forty two",
}
randomInt := RandomMapKey(f, m)
Expect(t, true, randomInt == 1 || randomInt == 5 || randomInt == 42)
}
func TestRandomMapValue(t *testing.T) {
f := New()
m := map[int]string{
1: "one",
5: "five",
42: "forty two",
}
randomStr := RandomMapValue(f, m)
Expect(t, true, randomStr == "one" || randomStr == "five" || randomStr == "forty two")
}