Skip to content

Commit

Permalink
Add mockFamilyName function (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkopehar authored Mar 18, 2024
1 parent 7c04598 commit c56a6bb
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
20 changes: 20 additions & 0 deletions assets/familyNames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- 'Smith',
- 'Johnson',
- 'Williams',
- 'Jones',
- 'Brown',
- 'Davis',
- 'Miller',
- 'Wilson',
- 'Moore',
- 'Taylor',
- 'Anderson',
- 'Thomas',
- 'Jackson',
- 'White',
- 'Harris',
- 'Martin',
- 'Thompson',
- 'Garcia',
- 'Martinez',
- 'Robinson',
3 changes: 2 additions & 1 deletion example/mock_data_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ void main() {
mockIPv6('e1b3:7bae:*:3474:*:c0cc:462:c4b9'); // Similar to IPv4 segments.
// ---------

// Mock first name.
// Mock names (names and surnames).
// ---------
mockName(); // Male of female first name(default).
mockName('male'); // Random male name.
mockName('female'); // Random female name.
mockFamilyName(); // Random surname.
// ---------

// Mock color from a given color model.
Expand Down
3 changes: 3 additions & 0 deletions lib/mock_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ library mock_data;

export 'src/mock_color.dart';
export 'src/mock_date.dart';
export 'src/mock_family_name.dart';
export 'src/mock_integer.dart';
export 'src/mock_ip.dart';
export 'src/mock_location.dart';
Expand Down Expand Up @@ -121,6 +122,8 @@ List<E> mockRange<E>(Function mockFunction, int numberOfMocks,
return List<E>.generate(numberOfMocks, (_) => mockFunction(format));
case 'mockName':
return List<E>.generate(numberOfMocks, (_) => mockFunction(gender));
case 'mockFamilyName':
return List<E>.generate(numberOfMocks, (_) => mockFunction());
case 'mockColor':
return List<E>.generate(numberOfMocks, (_) => mockFunction(returnModel));
case 'mockUrl':
Expand Down
20 changes: 20 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ var femaleNames = Set<String>.from([
'Samantha'
]);

var familyNames = Set<String>.from([
'Smith',
'Johnson',
'Williams',
'Jones',
'Brown',
'Miller',
'Wilson',
'Moore',
'Taylor',
'Anderson',
'Jackson',
'White',
'Thompson',
'Garcia',
'Martinez',
'Robinson',
'Jameson'
]);

// Random build parts for mockUrl function.
var path = <String>['foo', 'bar', 'buz', 'qux'];
var query = <String>['b=3', 'd=4', 'username=waldo', 'q=xyzzy'];
Expand Down
14 changes: 14 additions & 0 deletions lib/src/mock_family_name.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'constants.dart' show random, familyNames;

/// Generate random family name.
///
/// Returns `String` representing a family name.
///
/// For list of names, check [familyNames](https://github.com/dinkopehar/mock_data/blob/master/assets/familyNames.md).
///
/// Example usage:
/// ```dart
/// mockFamilyName() // returns family name.
/// ```
String mockFamilyName() =>
familyNames.elementAt(random.nextInt(familyNames.length));
12 changes: 12 additions & 0 deletions test/mock_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ void main() {
});
});

group('mockFamilyName tests', () {
test('Test mockFamilyName', () {
expect(familyNames, contains(mockFamilyName()));
});

test('Test mockFamilyName called from mockRange', () {
expect(mockRange(mockFamilyName, 10).length, equals(10));
expect(familyNames,
containsAll(mockRange(mockFamilyName, 15).toSet()));
});
});

group('mockColor tests', () {
test('Test mockColor only', () {
expect(mockColor(), startsWith('rgb'));
Expand Down

0 comments on commit c56a6bb

Please sign in to comment.