-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
boolean.go
34 lines (27 loc) · 850 Bytes
/
boolean.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
package faker
// Boolean is a faker struct for Boolean
type Boolean struct {
Faker *Faker
}
// Bool returns a fake bool for Faker
func (b Boolean) Bool() bool {
return b.Faker.IntBetween(0, 100) > 50
}
// BoolWithChance returns true with a given percentual chance that the value is true, otherwise returns false
func (b Boolean) BoolWithChance(chanceTrue int) bool {
if chanceTrue <= 0 {
return false
} else if chanceTrue >= 100 {
return true
}
return b.Faker.IntBetween(0, 100) < chanceTrue
}
// BoolInt returns a fake bool for Integer Boolean
func (b Boolean) BoolInt() int {
return b.Faker.RandomIntElement([]int{0, 1})
}
// BoolString returns a fake bool for string Boolean
func (b Boolean) BoolString(firstArg, secondArg string) string {
boolean := []string{firstArg, secondArg}
return b.Faker.RandomStringElement(boolean)
}