diff --git a/generator.go b/generator.go index 4c79543..00fd5e2 100644 --- a/generator.go +++ b/generator.go @@ -3,17 +3,26 @@ package persian_faker import ( "github.com/sepisoltani/persian-faker/providers/bank" "github.com/sepisoltani/persian-faker/providers/bill" + "github.com/sepisoltani/persian-faker/providers/digit" + "github.com/sepisoltani/persian-faker/providers/location" + "github.com/sepisoltani/persian-faker/providers/phonenumber" ) // DataGenerator is a facade for accessing all fake data generation functionalities. type DataGenerator struct { - Bank *bank.Bank - Bill *bill.Bill + Bank *bank.Bank + Bill *bill.Bill + Digit *digit.Digit + PhoneNumber *phonenumber.PhoneNumber + Location *location.Location } func NewDataGenerator() *DataGenerator { return &DataGenerator{ - Bank: &bank.Bank{}, - Bill: &bill.Bill{}, + Bank: &bank.Bank{}, + Bill: &bill.Bill{}, + Digit: &digit.Digit{}, + PhoneNumber: &phonenumber.PhoneNumber{}, + Location: &location.Location{}, } } diff --git a/providers/location/location.go b/providers/location/location.go index 49c432c..c80a84b 100644 --- a/providers/location/location.go +++ b/providers/location/location.go @@ -5,6 +5,8 @@ import ( "time" ) +var rng = rand.New(rand.NewSource(time.Now().UnixNano())) + var provinces = []string{ "آذربایجان شرقی", "آذربایجان غربی", "اردبیل", "اصفهان", "البرز", "ایلام", "بوشهر", "تهران", "چهارمحال و بختیاری", "خراسان جنوبی", @@ -223,23 +225,20 @@ var countries = []string{ "یونان", } -// RandomProvince returns a random province. -func RandomProvince() string { - src := rand.NewSource(time.Now().UnixNano()) - rng := rand.New(src) +type Location struct { +} + +// GenerateProvince returns a random province. +func (Location) GenerateProvince() string { return provinces[rng.Intn(len(provinces))] } -// RandomCity returns a random city. -func RandomCity() string { - src := rand.NewSource(time.Now().UnixNano()) - rng := rand.New(src) +// GenerateCity returns a random city. +func (Location) GenerateCity() string { return cities[rng.Intn(len(cities))] } -// RandomCountry returns a random country. -func RandomCountry() string { - src := rand.NewSource(time.Now().UnixNano()) - rng := rand.New(src) +// GenerateCountry returns a random country. +func (Location) GenerateCountry() string { return countries[rng.Intn(len(cities))] } diff --git a/providers/location/location_test.go b/providers/location/location_test.go index d208173..e4f99ed 100644 --- a/providers/location/location_test.go +++ b/providers/location/location_test.go @@ -4,9 +4,10 @@ import ( "testing" ) -// TestRandomProvince checks if the randomly selected province is from the list. -func TestRandomProvince(t *testing.T) { - randomProvince := RandomProvince() +// TestGenerateProvince checks if the randomly selected province is from the list. +func TestGenerateProvince(t *testing.T) { + location := &Location{} + randomProvince := location.GenerateProvince() found := false for _, province := range provinces { if province == randomProvince { @@ -15,13 +16,14 @@ func TestRandomProvince(t *testing.T) { } } if !found { - t.Errorf("RandomProvince returned a value not in the provinces list: %s", randomProvince) + t.Errorf("GenerateProvince returned a value not in the provinces list: %s", randomProvince) } } -// TestRandomCity checks if the randomly selected city is from the list. -func TestRandomCity(t *testing.T) { - randomCity := RandomCity() +// TestGenerateCity checks if the randomly selected city is from the list. +func TestGenerateCity(t *testing.T) { + location := &Location{} + randomCity := location.GenerateCity() found := false for _, city := range cities { if city == randomCity { @@ -30,13 +32,14 @@ func TestRandomCity(t *testing.T) { } } if !found { - t.Errorf("RandomCity returned a value not in the cities list: %s", randomCity) + t.Errorf("GenerateCity returned a value not in the cities list: %s", randomCity) } } -// TestRandomCountry checks if the randomly selected city is from the list. -func TestRandomCountry(t *testing.T) { - randomCountry := RandomCountry() +// TestGenerateCountry checks if the randomly selected city is from the list. +func TestGenerateCountry(t *testing.T) { + location := &Location{} + randomCountry := location.GenerateCountry() found := false for _, country := range countries { if country == randomCountry { @@ -45,6 +48,6 @@ func TestRandomCountry(t *testing.T) { } } if !found { - t.Errorf("RandomCountry returned a value not in the cities list: %s", randomCountry) + t.Errorf("GenerateCountry returned a value not in the cities list: %s", randomCountry) } } diff --git a/providers/phonenumber/phonenumber.go b/providers/phonenumber/phonenumber.go index 9f5179e..9e00775 100644 --- a/providers/phonenumber/phonenumber.go +++ b/providers/phonenumber/phonenumber.go @@ -8,11 +8,11 @@ import ( var rng = rand.New(rand.NewSource(time.Now().UnixNano())) -type phoneNumber struct { +type PhoneNumber struct { } // GeneratePersianMobileNumber generates a Persian mobile phone number. -func (phoneNumber) GeneratePersianMobileNumber() string { +func (PhoneNumber) GeneratePersianMobileNumber() string { prefixes := []string{"0912", "0913", "0914", "0915", "0916"} prefix := prefixes[rng.Intn(len(prefixes))]