Skip to content

Commit

Permalink
Added faker.RandomIntElement
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswdr committed Aug 10, 2018
1 parent 5a81f8c commit 62e54f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func (f Faker) RandomStringElement(s []string) string {
return s[i]
}

func (f Faker) RandomIntElement(a []int) int {
i := f.IntBetween(0, len(a)-1)
return a[i]
}

func (f Faker) ShuffleString(s string) string {
orig := strings.Split(s, "")
dest := make([]string, len(orig))
Expand Down
13 changes: 13 additions & 0 deletions faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func TestRandomLetter(t *testing.T) {
Expect(t, 1, len(value))
}

func TestRandomIntElement(t *testing.T) {
f := New()
elements := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
element := f.RandomIntElement(elements)
found := false
for _, i := range elements {
if i == element {
found = true
}
}
Expect(t, true, found)
}

func TestShuffleString(t *testing.T) {
f := New()
orig := "foo bar"
Expand Down

0 comments on commit 62e54f8

Please sign in to comment.