-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3960 from allbertoMD/main
Reto #26 - Swift
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
// Se aconseja usar el script en Playground para poder usar XCTest | ||
|
||
func isFriday13th(month: Int, year: Int) -> Bool { | ||
|
||
let calendar = Calendar.current | ||
var components = DateComponents() | ||
|
||
components.year = year | ||
components.month = month | ||
components.day = 13 | ||
|
||
if let date = calendar.date(from: components) { | ||
let weekday = calendar.component(.weekday, from: date) | ||
return weekday == 6 | ||
} | ||
|
||
return false | ||
} | ||
|
||
class IsFriday13thTests: XCTestCase { | ||
|
||
func testIsFriday13th() { | ||
|
||
XCTAssertTrue(isFriday13th(month: 8, year: 2021)) | ||
XCTAssertTrue(isFriday13th(month: 1, year: 2023)) | ||
|
||
|
||
XCTAssertFalse(isFriday13th(month: 5, year: 2023)) | ||
XCTAssertFalse(isFriday13th(month: 7, year: 2025)) | ||
} | ||
} | ||
|
||
IsFriday13thTests.defaultTestSuite.run() | ||
|
||
|
||
|
||
|