-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Foundation | ||
|
||
/** | ||
* AddressGenerator is a utility class for generating random addresses. | ||
* - Description: This class provides static methods and data arrays to generate random addresses, | ||
* including street numbers, street names, street types, cities, states, and zip codes. | ||
* It can be used for testing, mocking, or any other situation where random address data is needed. | ||
*/ | ||
public class AddressGenerator { | ||
/// An array of common street names. | ||
private static let streetNames = ["Main", "High", "Maple", "Oak", "Pine", "Cedar", "Elm", "Washington", "Lake", "Hill"] | ||
|
||
/// An array of common street types. | ||
private static let streetTypes = ["St", "Ave", "Blvd", "Rd", "Ln", "Way"] | ||
|
||
/// An array of major US cities. | ||
private static let cities = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"] | ||
|
||
/// An array of US state abbreviations. | ||
private static let states = ["NY", "CA", "IL", "TX", "AZ"] | ||
|
||
/// An array of example zip codes corresponding to the cities. | ||
private static let zipCodes = ["10001", "90001", "60601", "77001", "85001"] | ||
|
||
/** | ||
* Generates a random address string. | ||
* - Description: Combines random elements from the street names, street types, cities, states, and zip codes arrays | ||
* to create a realistic random address. The street number is randomly generated between 1 and 9999. | ||
* - Returns: A string representing a random address in the format "1234 Main St, City, State ZIP". | ||
* ## Examples: | ||
* ``` | ||
* let address = AddressGenerator.randomAddress() | ||
* print(address) // "123 Maple Ave, Chicago, IL 60601" | ||
* ``` | ||
*/ | ||
public static func randomAddress() -> String { | ||
let number = Int.random(in: 1...9999) | ||
let streetName = streetNames.randomElement()! | ||
let streetType = streetTypes.randomElement()! | ||
let city = cities.randomElement()! | ||
let state = states.randomElement()! | ||
let zipCode = zipCodes.randomElement()! | ||
return "\(number) \(streetName) \(streetType), \(city), \(state) \(zipCode)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
[![Tests](https://github.com/sentryco/MockGen/actions/workflows/tests.yml/badge.svg)](https://github.com/sentryco/MockGen/actions/workflows/tests.yml) | ||
[![codebeat badge](https://codebeat.co/badges/6f474052-1ae2-4c61-b72f-dcd23e442278)](https://codebeat.co/projects/github-com-sentryco-mockgen-main) | ||
[![Swift Version](https://img.shields.io/badge/Swift-5.9-orange.svg)](https://swift.org) | ||
![Platforms](https://img.shields.io/badge/platforms-macOS%20|%20iOS-blue.svg) | ||
|
||
# 🧪 MockGen | ||
|
||
|
@@ -84,6 +86,49 @@ let randomStreetAddress = MockGen.randomStreetAddress // Returns a random street | |
let randomCity = MockGen.randomCity // Returns a random city name. | ||
let randomState = MockGen.randomState // Returns a random state abbreviation. | ||
let randomZipCode = MockGen.randomZipCode // Returns a random zip code. | ||
// e.g., "123 Main St, Springfield, IL 62704" | ||
let randomAddress = MockGen.randomAddress // Returns a random street address. | ||
let randomSSID = MockGen.randomSSID // Returns a random Wi-Fi SSID. | ||
let randomIssuer = MockGen.randomIssuer // Returns a random issuer name. | ||
let randomBrand = MockGen.randomBrand // Returns a random brand name. | ||
let randomOTP = MockGen.randomOTP // Returns a random OTP URL. | ||
``` | ||
|
||
## Generating Random User Profiles | ||
|
||
MockGen can generate comprehensive user profiles combining multiple data points: | ||
|
||
```swift | ||
struct UserProfile { | ||
let fullName: String | ||
let email: String | ||
let phoneNumber: String | ||
let address: String | ||
} | ||
|
||
extension MockGen { | ||
static var randomUserProfile: UserProfile { | ||
let fullName = randomFullName ?? "John Doe" | ||
let email = getEmail(name: fullName, brand: randomBrand ?? "example.com") ?? "[email protected]" | ||
let phoneNumber = randomPhoneNumber() | ||
let address = randomAddress ?? "123 Main St" | ||
return UserProfile(fullName: fullName, email: email, phoneNumber: phoneNumber, address: address) | ||
} | ||
} | ||
|
||
// Usage | ||
let userProfile = MockGen.randomUserProfile | ||
print(userProfile.fullName) // e.g., "Jane Smith" | ||
print(userProfile.email) // e.g., "[email protected]" | ||
print(userProfile.phoneNumber) // e.g., "(555) 123-4567" | ||
print(userProfile.address) // e.g., "456 Elm St, Anytown, CA 90210" | ||
``` | ||
|
||
The `SecRan` class provides methods for generating secure random secrets. Including usage examples will demonstrate how to generate cryptographically secure secrets. | ||
|
||
```swift | ||
let secret = SecRan.randomSecret(length: 16) // Generates a random secret string of length 16. | ||
let secretInRange = SecRan.randomSecret(min: 8, max: 32) // Generates a random secret string with length between 8 and 32. | ||
``` | ||
|
||
## FAQ: | ||
|