Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lat long #63

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/faker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ void main() {
print(faker.person.firstName());
print(faker.sport.name());

// Generate a random geo.
print(faker.geo.longitude());
print(faker.geo.latitude());

// Generate a random amount of IP v4 addresses (max 10).
print(random.amount((_) => faker.internet.ipv4Address(), 10));

Expand Down
4 changes: 3 additions & 1 deletion lib/src/faker.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:faker/src/date.dart';
import 'package:faker/src/geo.dart';
import 'package:faker/src/lorem.dart';
import 'package:faker/src/phone_number.dart';
import 'package:faker/src/providers/default_providers.dart';
Expand All @@ -21,7 +22,6 @@ import 'providers/base_providers.dart';
import 'random_generator.dart';
import 'sport.dart';
import 'vehicle.dart';
import 'animals.dart';

final Faker faker = Faker.withGenerator(random);

Expand All @@ -32,6 +32,7 @@ class Faker {
final Company company;
final Currency currency;
final Food food;
final Geo geo;
final Guid guid;
final Image image;
final Internet internet;
Expand All @@ -53,6 +54,7 @@ class Faker {
company = Company(Person(random)),
currency = Currency(random),
food = Food(random),
geo = Geo(random),
guid = Guid(random),
image = Image(),
internet = Internet(random),
Expand Down
23 changes: 23 additions & 0 deletions lib/src/geo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'random_generator.dart';

class Geo {
const Geo(this._random);

final RandomGenerator _random;

/// Generates a longitude.
///
/// Example:
/// ```dart
/// faker.geo.longitude();
/// ```
double longitude() => -180 + _random.decimal() * 180 * 2;

/// Generates a latitude.
///
/// Example:
/// ```dart
/// faker.geo.latitude();
/// ```
double latitude() => -90 + _random.decimal() * 90 * 2;
}
2 changes: 2 additions & 0 deletions test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'specs/conference.dart' as conference;
import 'specs/currency.dart' as currency;
import 'specs/date.dart' as date;
import 'specs/food.dart' as food;
import 'specs/geo.dart' as geo;
import 'specs/guid.dart' as guid;
import 'specs/image.dart' as image;
import 'specs/internet.dart' as internet;
Expand All @@ -23,6 +24,7 @@ void main() {
company.main();
currency.main();
food.main();
geo.main();
guid.main();
image.main();
internet.main();
Expand Down
2 changes: 1 addition & 1 deletion test/specs/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {

group('date', () {
test('should be able to generate a DateTime', () {
expect(true, faker.date.dateTime() is DateTime);
expect(faker.date.dateTime(), isA<DateTime>());
});

test('should be able to generate a DateTime between 2 DateTimes', () {
Expand Down
24 changes: 24 additions & 0 deletions test/specs/geo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:test/test.dart';
import 'package:faker/faker.dart';

void main() {
group('geo', () {
test('should be able to generate a longitude', () {
expect(
faker.geo.longitude(),
allOf(
greaterThanOrEqualTo(-180),
lessThanOrEqualTo(180),
));
});

test('should be able to generate a latitude', () {
expect(
faker.geo.latitude(),
allOf(
greaterThanOrEqualTo(-90),
lessThanOrEqualTo(90),
));
});
});
}
2 changes: 1 addition & 1 deletion test/specs/phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void main() {
// '+49 (0)### ######x##',
matches(r'\+49 \(0\)\d{3} \d{6}x\d{2}'),
// '+49 (0)### ######/##',
matches(r'\+49 \(0\)\d{3} \d{6}x\d{2}'),
matches(r'\+49 \(0\)\d{3} \d{6}/\d{2}'),
// '0049 (###) ########',
matches(r'0049 \(\d{3}\) \d{8}'),
// '0049 (###) # #######',
Expand Down