Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Jun 7, 2023
2 parents 48ce994 + fbfd9b1 commit d3c737a
Show file tree
Hide file tree
Showing 15 changed files with 864 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Random data generator written in go
- [Issue](https://github.com/brianvoe/gofakeit/issues)

## Contributors

Thanks to everyone who has contributed to Gofakeit!

<a href="https://github.com/brianvoe/gofakeit/graphs/contributors">
Expand Down Expand Up @@ -285,6 +286,7 @@ Name() string
NamePrefix() string
NameSuffix() string
FirstName() string
MiddleName() string
LastName() string
Gender() string
SSN() string
Expand Down Expand Up @@ -588,13 +590,15 @@ Isin() string

```go
BS() string
Blurb() string
BuzzWord() string
Company() string
CompanySuffix() string
Job() *JobInfo
JobDescriptor() string
JobLevel() string
JobTitle() string
Slogan() string
```

### Hacker
Expand Down Expand Up @@ -725,6 +729,23 @@ MinecraftBiome() string
MinecraftWeather() string
```

### Book

```go
Book() *BookInfo
BookTitle() string
BookAuthor() string
BookGenre() string
```

### Movie

```go
Movie() *MovieInfo
MovieName() string
MovieGenre() string
```

### Error

Unlike most `gofakeit` methods which return a `string`, the error methods return a Go `error`. Access the error message as a string by chaining the `.Error()` method.
Expand All @@ -738,4 +759,4 @@ ErrorHTTPClient() error
ErrorHTTPServer() error
ErrorInput() error
ErrorRuntime() error
```
```
85 changes: 85 additions & 0 deletions book.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package gofakeit

import "math/rand"

func BookTitle() string { return bookTitle(globalFaker.Rand) }

func (f *Faker) BookTitle() string { return bookTitle(f.Rand) }

func bookTitle(r *rand.Rand) string { return getRandValue(r, []string{"book", "title"}) }

func BookAuthor() string { return bookAuthor(globalFaker.Rand) }

func (f *Faker) BookAuthor() string { return bookAuthor(f.Rand) }

func bookAuthor(r *rand.Rand) string { return getRandValue(r, []string{"book", "author"}) }

func BookGenre() string { return bookGenre(globalFaker.Rand) }

func (f *Faker) BookGenre() string { return bookGenre(f.Rand) }

func bookGenre(r *rand.Rand) string { return getRandValue(r, []string{"book", "genre"}) }

type BookInfo struct {
Title string `json:"title" xml:"name"`
Author string `json:"author" xml:"author"`
Genre string `json:"genre" xml:"genre"`
}

func Book() *BookInfo { return book(globalFaker.Rand) }

func (f *Faker) Book() *BookInfo { return book(f.Rand) }

func book(r *rand.Rand) *BookInfo {
return &BookInfo{
Title: bookTitle(r),
Author: bookAuthor(r),
Genre: bookGenre(r),
}
}

func addBookLookup() {
AddFuncLookup("book", Info{
Display: "Book",
Category: "book",
Description: "Random Book data set",
Example: `{title: "Hamlet", author: "Mark Twain", genre: "Adventure"}`,
Output: "map[string]string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return book(r), nil
},
})

AddFuncLookup("booktitle", Info{
Display: "Title",
Category: "book",
Description: "Random Book title",
Example: "Hamlet",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookTitle(r), nil
},
})

AddFuncLookup("bookauthor", Info{
Display: "Author",
Category: "book",
Description: "Random Book author",
Example: "Mark Twain",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookAuthor(r), nil
},
})

AddFuncLookup("bookgenre", Info{
Display: "Genre",
Category: "book",
Description: "Random Book genre",
Example: "Adventure",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return bookGenre(r), nil
},
})
}
167 changes: 167 additions & 0 deletions book_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package gofakeit

import (
"fmt"
"testing"
)

func EnableBook() {
Seed(11)
book := Book()
fmt.Println(book.Title)
fmt.Println(book.Author)
fmt.Println(book.Genre)
// Output: Anna Karenina
// Toni Morrison
// Thriller
}

func ExampleFaker_Book() {
f := New(11)
book := f.Book()
fmt.Println(book.Title)
fmt.Println(book.Author)
fmt.Println(book.Genre)
// Output: Anna Karenina
// Toni Morrison
// Thriller
}

func BenchmarkBook(b *testing.B) {
b.Run("package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
Book()
}
})

b.Run("Faker math", func(b *testing.B) {
f := New(0)

for i := 0; i < b.N; i++ {
f.Book()
}
})

b.Run("Faker crypto", func(b *testing.B) {
f := NewCrypto()

for i := 0; i < b.N; i++ {
f.Book()
}
})
}

func TestBook(t *testing.T) {
for i := 0; i < 100; i++ {
Book()
}
}

func ExampleBookTitle() {
Seed(11)
fmt.Println(BookTitle())
// Output: Anna Karenina
}

func ExampleFaker_BookTitle() {
f := New(11)
fmt.Println(f.BookTitle())
// Output: Anna Karenina
}

func BenchmarkBookTitle(b *testing.B) {
b.Run("package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
BookTitle()
}
})

b.Run("Faker math", func(b *testing.B) {
f := New(0)

for i := 0; i < b.N; i++ {
f.BookTitle()
}
})

b.Run("Faker crypto", func(b *testing.B) {
f := NewCrypto()

for i := 0; i < b.N; i++ {
f.BookTitle()
}
})
}

func ExampleBookAuthor() {
Seed(11)
fmt.Println(BookAuthor())
// Output: James Joyce
}

func ExampleFaker_BookAuthor() {
f := New(11)
fmt.Println(f.BookAuthor())
// Output: James Joyce
}

func BenchmarkBookAuthor(b *testing.B) {
b.Run("package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
BookAuthor()
}
})

b.Run("Faker math", func(b *testing.B) {
f := New(0)

for i := 0; i < b.N; i++ {
f.BookAuthor()
}
})

b.Run("Faker crypto", func(b *testing.B) {
f := NewCrypto()

for i := 0; i < b.N; i++ {
f.BookAuthor()
}
})
}


func ExampleBookGenre() {
Seed(11)
fmt.Println(BookGenre())
// Output: Crime
}

func ExampleFaker_BookGenre() {
f := New(11)
fmt.Println(f.BookGenre())
// Output: Crime
}

func BenchmarkBookGenre(b *testing.B) {
b.Run("package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
BookGenre()
}
})

b.Run("Faker math", func(b *testing.B) {
f := New(0)

for i := 0; i < b.N; i++ {
f.BookGenre()
}
})

b.Run("Faker crypto", func(b *testing.B) {
f := NewCrypto()

for i := 0; i < b.N; i++ {
f.BookGenre()
}
})
}
53 changes: 53 additions & 0 deletions company.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func (f *Faker) CompanySuffix() string { return companySuffix(f.Rand) }

func companySuffix(r *rand.Rand) string { return getRandValue(r, []string{"company", "suffix"}) }

// Blurb will generate a random company blurb string
func Blurb() string { return blurb(globalFaker.Rand) }

func (f *Faker) Blurb() string { return blurb(f.Rand) }

func blurb(r *rand.Rand) string { return getRandValue(r, []string{"company", "blurb"}) }

// BuzzWord will generate a random company buzz word string
func BuzzWord() string { return buzzWord(globalFaker.Rand) }

Expand Down Expand Up @@ -81,6 +88,30 @@ func (f *Faker) JobLevel() string { return jobLevel(f.Rand) }

func jobLevel(r *rand.Rand) string { return getRandValue(r, []string{"job", "level"}) }

// Slogan will generate a random company slogan
func Slogan() string { return slogan(globalFaker.Rand) }

// Slogan will generate a random company slogan
func (f *Faker) Slogan() string { return slogan(f.Rand) }

// Slogan will generate a random company slogan
func slogan(r *rand.Rand) string {
slogan := ""
var sloganStyle = number(r, 0, 2)
switch sloganStyle {
// Noun. Buzzword!
case 0:
slogan = getRandValue(r, []string{"company", "blurb"}) + ". " + getRandValue(r, []string{"company", "buzzwords"}) + "!"
// Buzzword Noun, Buzzword Noun.
case 1:
slogan = getRandValue(r, []string{"company", "buzzwords"}) + " " + getRandValue(r, []string{"company", "blurb"}) + ", " + getRandValue(r, []string{"company", "buzzwords"}) + " " + getRandValue(r, []string{"company", "blurb"}) + "."
// Buzzword bs Noun, Buzzword.
case 2:
slogan = getRandValue(r, []string{"company", "buzzwords"}) + " " + getRandValue(r, []string{"company", "bs"}) + " " + getRandValue(r, []string{"company", "blurb"}) + ", " + getRandValue(r, []string{"company", "buzzwords"}) + "."
}
return slogan
}

func addCompanyLookup() {
AddFuncLookup("company", Info{
Display: "Company",
Expand Down Expand Up @@ -115,6 +146,17 @@ func addCompanyLookup() {
},
})

AddFuncLookup("blurb", Info{
Display: "Blurb",
Category: "company",
Description: "Random company blurb",
Example: "word",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return blurb(r), nil
},
})

AddFuncLookup("buzzword", Info{
Display: "Buzzword",
Category: "company",
Expand Down Expand Up @@ -169,4 +211,15 @@ func addCompanyLookup() {
return jobLevel(r), nil
},
})

AddFuncLookup("slogan", Info{
Display: "Slogan",
Category: "comapny",
Description: "Random company slogan",
Example: "Universal seamless Focus, interactive.",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return slogan(r), nil
},
})
}
Loading

0 comments on commit d3c737a

Please sign in to comment.