Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Jan 23, 2025
1 parent af95797 commit 32dc9b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/MockGen/MockGen+Getter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension MockGen {
}
// fixme: add doc
// fixme: add unit-test
func static func randomDate(from startDate: Date, to endDate: Date) -> Date {
public static func randomDate(from startDate: Date, to endDate: Date) -> Date {
let timeInterval = endDate.timeIntervalSince(startDate)
let randomInterval = TimeInterval.random(in: 0...timeInterval)
return startDate.addingTimeInterval(randomInterval)
Expand Down
24 changes: 13 additions & 11 deletions Tests/MockGenTests/UnitTests.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import XCTest
@testable import MockGen

final class MockGenTests: XCTestCase {
// tests for edge cases like zero length passwords.
func testGeneratePasswordWithZeroLength() {
let password = CodeGen.generatePassword(length: 0)
XCTAssertTrue(password.isEmpty, "Password should be empty when length is zero.")
}
/**
final class UnitTests: XCTestCase {
// tests for edge cases like zero length passwords.
func testGeneratePasswordWithZeroLength() {
Swift.print("testGeneratePasswordWithZeroLength")
let password = CodeGen.generatePassword(length: 0)
XCTAssertTrue(password.isEmpty, "Password should be empty when length is zero.")
}
/**
* Tests the `randomAddress` property of `MockGen`
* - Description: Verifies that the `randomAddress` returns a non-empty string. Optionally, you can check if it matches a specific address format using a regular expression.
*/
func testRandomAddress() {
func testRandomAddress() {
// Act
let address = MockGen.randomAddress

// Assert
XCTAssertFalse(address.isEmpty, "The randomAddress should not be empty")

// Optionally, verify the address format using a regular expression
let addressPattern = "^[0-9]+\\s+[A-Za-z]+\\s+[A-Za-z]+,\\s+[A-Za-z\\s]+,\\s+[A-Za-z]{2}\\s+[0-9]{5}$"
let regex = try! NSRegularExpression(pattern: addressPattern)
let range = NSRange(location: 0, length: address.utf16.count)
let match = regex.firstMatch(in: address, options: [], range: range)
XCTAssertNotNil(match, "The randomAddress does not match the expected format")
}
}
}
}

0 comments on commit 32dc9b3

Please sign in to comment.