From 812e7f05d8561406321fdb9da7d1dd98241cc7da Mon Sep 17 00:00:00 2001 From: allbertoMD Date: Wed, 28 Jun 2023 18:04:32 +0200 Subject: [PATCH] Reto #26 - Swift --- .../swift/allbertoMD.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Retos/Reto #26 - TESTING [Media]/swift/allbertoMD.swift 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() + + + +