diff --git a/Retos/Reto #26 - TESTING [Media]/swift/allbertoMD.swift b/Retos/Reto #26 - TESTING [Media]/swift/allbertoMD.swift new file mode 100644 index 0000000000..b8a4ac3735 --- /dev/null +++ b/Retos/Reto #26 - TESTING [Media]/swift/allbertoMD.swift @@ -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() + + + +