From bb82bde63140470a4760b18fb2c8a9b6b2ba8870 Mon Sep 17 00:00:00 2001 From: meatball Date: Sun, 22 Dec 2024 22:23:23 +0100 Subject: [PATCH] Update Swift tools version to 6.0 and testing files --- .../freelancer-rates/.meta/config.json | 2 +- .../concept/freelancer-rates/Package.swift | 5 +- .../FreelancerRates/FreelancerRates.swift | 13 +- .../FreelancerRatesTests.swift | 83 ++++++----- exercises/concept/lasagna/.meta/config.json | 2 +- exercises/concept/lasagna/Package.swift | 2 +- .../Tests/LasagnaTests/LasagnaTests.swift | 70 +++++----- exercises/concept/wings-quest/Package.swift | 2 +- .../WingsQuestTests/WingsQuestTests.swift | 132 +++++++----------- 9 files changed, 138 insertions(+), 173 deletions(-) diff --git a/exercises/concept/freelancer-rates/.meta/config.json b/exercises/concept/freelancer-rates/.meta/config.json index bb062a7b5..935ced310 100644 --- a/exercises/concept/freelancer-rates/.meta/config.json +++ b/exercises/concept/freelancer-rates/.meta/config.json @@ -14,7 +14,7 @@ ".meta/Sources/FreelancerRates/FreelancerRatesExemplar.swift" ] }, - "language_versions": ">=5.0", + "language_versions": ">=6.0", "forked_from": [ "javascript/freelancer-rates" ], diff --git a/exercises/concept/freelancer-rates/Package.swift b/exercises/concept/freelancer-rates/Package.swift index aea08b630..89aab65e7 100644 --- a/exercises/concept/freelancer-rates/Package.swift +++ b/exercises/concept/freelancer-rates/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -14,6 +14,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -23,6 +24,6 @@ let package = Package( dependencies: []), .testTarget( name: "FreelancerRatesTests", - dependencies: ["FreelancerRates"]), + dependencies: ["FreelancerRates", .product(name: "Numerics", package: "swift-numerics"),]), ] ) diff --git a/exercises/concept/freelancer-rates/Sources/FreelancerRates/FreelancerRates.swift b/exercises/concept/freelancer-rates/Sources/FreelancerRates/FreelancerRates.swift index 4b8f954bf..4917ac166 100644 --- a/exercises/concept/freelancer-rates/Sources/FreelancerRates/FreelancerRates.swift +++ b/exercises/concept/freelancer-rates/Sources/FreelancerRates/FreelancerRates.swift @@ -1,11 +1,18 @@ +let hoursPerDay = 8 +let daysPerMonth = 22 + func dailyRateFrom(hourlyRate: Int) -> Double { - fatalError("Please implement the dailyRateFrom(hourlyRate:) function") + return Double(hourlyRate * hoursPerDay) } func monthlyRateFrom(hourlyRate: Int, withDiscount discount: Double) -> Double { - fatalError("Please implement the monthlyRateFrom(hourlyRate:withDiscount:) function") + let monthly = Double(hourlyRate * hoursPerDay * daysPerMonth) * (1.0 - (discount / 100)) + return monthly.rounded() } func workdaysIn(budget: Double, hourlyRate: Int, withDiscount discount: Double) -> Double { - fatalError("Please implement the workdaysIn(budget:hourlyRate:withDiscount:) function") + let fullMonthlyRate = budget / (1.0 - (discount / 100)) + let hours = fullMonthlyRate / Double(hourlyRate) + let days = hours / Double(hoursPerDay) + return days.rounded(.down) } diff --git a/exercises/concept/freelancer-rates/Tests/FreelancerRatesTests/FreelancerRatesTests.swift b/exercises/concept/freelancer-rates/Tests/FreelancerRatesTests/FreelancerRatesTests.swift index c24fb4a44..770dccbd1 100644 --- a/exercises/concept/freelancer-rates/Tests/FreelancerRatesTests/FreelancerRatesTests.swift +++ b/exercises/concept/freelancer-rates/Tests/FreelancerRatesTests/FreelancerRatesTests.swift @@ -1,70 +1,65 @@ -import XCTest +import Testing +import Foundation +import Numerics @testable import FreelancerRates -let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false -class TaskDailyRateFrom: XCTestCase { - func testdailyRateFromFor60() { - XCTAssertEqual(dailyRateFrom(hourlyRate: 60), 480.0, accuracy: 0.001) +@Suite struct FreelancerRatesTests { + @Test("Daily rate from hourly rate") + func testTaskDailyRateFrom() { + #expect(dailyRateFrom(hourlyRate: 60).isApproximatelyEqual(to: 480.0, relativeTolerance: 0.002)) } - func testdailyRateFromFor16() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(dailyRateFrom(hourlyRate: 16), 128.0, accuracy: 0.001) + @Test("Daily rate from hourly rate with 16 as rate", .enabled(if: RUNALL)) + func testTaskDailyRateFromFor16() { + #expect(dailyRateFrom(hourlyRate: 16).isApproximatelyEqual(to: 128.0, relativeTolerance: 0.002)) } - func testdailyRateFromFor25() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(dailyRateFrom(hourlyRate: 25), 200.0, accuracy: 0.001) + @Test("Daily rate from hourly rate with 25 as rate", .enabled(if: RUNALL)) + func testTaskDailyRateFromFor25() { + #expect(dailyRateFrom(hourlyRate: 25).isApproximatelyEqual(to: 200.0, relativeTolerance: 0.002)) } -} -class TaskMonthlyRateFrom: XCTestCase { - func testmonthlyWithWholeResult() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(monthlyRateFrom(hourlyRate: 80, withDiscount: 50), 7040, accuracy: 0.001) + @Test("Montly rate with whole result", .enabled(if: RUNALL)) + func testmonthlyWithWholeResult() { + #expect(monthlyRateFrom(hourlyRate: 80, withDiscount: 50).isApproximatelyEqual(to: 7040, relativeTolerance: 0.001)) } - func testmonthlyRoundDown() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(monthlyRateFrom(hourlyRate: 77, withDiscount: 10.5), 12129, accuracy: 0.001) + @Test("Montly rate round down", .enabled(if: RUNALL)) + func testmonthlyRoundDown() { + #expect(monthlyRateFrom(hourlyRate: 77, withDiscount: 10.5).isApproximatelyEqual(to: 12129, relativeTolerance: 0.001)) } - func testmonthlyRoundUp() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(monthlyRateFrom(hourlyRate: 80, withDiscount: 10.5), 12602, accuracy: 0.001) + @Test("Montly rate round up", .enabled(if: RUNALL)) + func testmonthlyRoundUp() { + #expect(monthlyRateFrom(hourlyRate: 80, withDiscount: 10.5).isApproximatelyEqual(to: 12602, relativeTolerance: 0.001)) } -} -class TaskWorkdaysIn: XCTestCase { - func testworkdaysInSmallBudget() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - workdaysIn(budget: 1000, hourlyRate: 50, withDiscount: 10), 2.0, accuracy: 0.001) + + @Test("Workdays in small budget", .enabled(if: RUNALL)) + func testworkdaysInSmallBudget() { + #expect(workdaysIn(budget: 1000, hourlyRate: 50, withDiscount: 10).isApproximatelyEqual(to: 2.0, relativeTolerance: 0.001)) } - func testworkdaysInMediumBudget() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - workdaysIn(budget: 5000, hourlyRate: 60, withDiscount: 10), 11.0, accuracy: 0.001) + @Test("Workdays in medium budget", .enabled(if: RUNALL)) + func testworkdaysInMediumBudget() { + #expect(workdaysIn(budget: 5000, hourlyRate: 60, withDiscount: 10).isApproximatelyEqual(to: 11.0, relativeTolerance: 0.001)) } - func testworkdaysLargebudget() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 10), 43.0, accuracy: 0.001) + @Test("Workdays large budget", .enabled(if: RUNALL)) + func testworkdaysLargebudget() { + #expect(workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 10).isApproximatelyEqual(to: 43.0, relativeTolerance: 0.001)) } - func testworkdaysShouldRound() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - workdaysIn(budget: 20000, hourlyRate: 80, withDiscount: 11), 35.0, accuracy: 0.001) + @Test("Workdays should round", .enabled(if: RUNALL)) + func testworkdaysShouldRound() { + #expect(workdaysIn(budget: 20000, hourlyRate: 80, withDiscount: 11).isApproximatelyEqual(to: 35.0, relativeTolerance: 0.001)) } - func testworkdaysShouldNotRoundToNearstInteger() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 11), 43.0, accuracy: 0.001) + @Test("Workdays should not round to nearst integer", .enabled(if: RUNALL)) + func testworkdaysShouldNotRoundToNearstInteger() { + #expect(workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 11).isApproximatelyEqual(to: 43.0, relativeTolerance: 0.001)) } } diff --git a/exercises/concept/lasagna/.meta/config.json b/exercises/concept/lasagna/.meta/config.json index ce1064ba8..c4a5464ef 100644 --- a/exercises/concept/lasagna/.meta/config.json +++ b/exercises/concept/lasagna/.meta/config.json @@ -14,7 +14,7 @@ ".meta/Sources/Lasagna/LasagnaExemplar.swift" ] }, - "language_versions": ">=5.0", + "language_versions": ">=6.0", "forked_from": [ "fsharp/lucians-luscious-lasagna" ], diff --git a/exercises/concept/lasagna/Package.swift b/exercises/concept/lasagna/Package.swift index 95189ce51..aa6aabc4f 100644 --- a/exercises/concept/lasagna/Package.swift +++ b/exercises/concept/lasagna/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.swift b/exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.swift index 9d4fae81d..8050e91f0 100644 --- a/exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.swift +++ b/exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.swift @@ -1,62 +1,58 @@ -import XCTest +import Testing +import Foundation @testable import Lasagna -let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false -class TaskExpectedMinutesInOvenTests: XCTestCase { +@Suite struct LasagnaTests { + @Test("Expected minutes in oven") func testExpectedMinutes() { - XCTAssertEqual(expectedMinutesInOven, 40) + #expect(expectedMinutesInOven == 40) } -} -class TaskRemainingMinutesInOven: XCTestCase { - func testRemainingMinutes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 13), 27) + @Test("Remaining minutes in oven", .enabled(if: RUNALL)) + func testRemainingMinutes() { + #expect(remainingMinutesInOven(elapsedMinutes: 13) == 27) } - func testRemainingMinutesWhenDone() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 40), 0) + @Test("Remaining minutes in oven when done", .enabled(if: RUNALL)) + func testRemainingMinutesWhenDone() { + #expect(remainingMinutesInOven(elapsedMinutes: 40) == 0) } - func testRemainingMinutesWhenLessThanOne() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 39), 1) + @Test("Remaining minutes in oven when less than one", .enabled(if: RUNALL)) + func testRemainingMinutesWhenLessThanOne() { + #expect(remainingMinutesInOven(elapsedMinutes: 39) == 1) } -} -class TaskPreparationTimeInMinutes: XCTestCase { - func testPreparationMinutes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(preparationTimeInMinutes(layers: 6), 12) + @Test("Preparation time in minutes", .enabled(if: RUNALL)) + func testPreparationMinutes() { + #expect(preparationTimeInMinutes(layers: 6) == 12) } - func testPreparationMinutesForOneLayer() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(preparationTimeInMinutes(layers: 1), 2) + @Test("Preparation time in minutes for one layer", .enabled(if: RUNALL)) + func testPreparationMinutesForOneLayer() { + #expect(preparationTimeInMinutes(layers: 1) == 2) } - func testPreparationMinutesForZeroLayers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(preparationTimeInMinutes(layers: 0), 0) + @Test("Preparation time in minutes for zero layers", .enabled(if: RUNALL)) + func testPreparationMinutesForZeroLayers() { + #expect(preparationTimeInMinutes(layers: 0) == 0) } -} -class TaskTotalTimeInMinutes: XCTestCase { - func testTotalMinutes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(totalTimeInMinutes(layers: 1, elapsedMinutes: 30), 32) + @Test("Total time in minutes", .enabled(if: RUNALL)) + func testTotalMinutes() { + #expect(totalTimeInMinutes(layers: 1, elapsedMinutes: 30) == 32) } - func testTotalMinutesWhenDone() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(totalTimeInMinutes(layers: 2, elapsedMinutes: 25), 29) + @Test("Total time in minutes when done", .enabled(if: RUNALL)) + func testTotalMinutesWhenDone() { + #expect(totalTimeInMinutes(layers: 2, elapsedMinutes: 25) == 29) } - func testTotalMinutesWhenLessThanOne() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(totalTimeInMinutes(layers: 4, elapsedMinutes: 8), 16) + @Test("Total time in minutes when less than one", .enabled(if: RUNALL)) + func testTotalMinutesWhenLessThanOne() { + #expect(totalTimeInMinutes(layers: 4, elapsedMinutes: 8) == 16) } } diff --git a/exercises/concept/wings-quest/Package.swift b/exercises/concept/wings-quest/Package.swift index 4ce34d013..c80d8a409 100644 --- a/exercises/concept/wings-quest/Package.swift +++ b/exercises/concept/wings-quest/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/exercises/concept/wings-quest/Tests/WingsQuestTests/WingsQuestTests.swift b/exercises/concept/wings-quest/Tests/WingsQuestTests/WingsQuestTests.swift index 0c1f316e1..2599aed28 100644 --- a/exercises/concept/wings-quest/Tests/WingsQuestTests/WingsQuestTests.swift +++ b/exercises/concept/wings-quest/Tests/WingsQuestTests/WingsQuestTests.swift @@ -1,117 +1,83 @@ -import XCTest +import Testing +import Foundation @testable import WingsQuest -let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false -class TaskBonusPoints: XCTestCase { - func testGetsBonusPoints() { - XCTAssertTrue( - bonusPoints(powerUpActive: true, touchingEagle: true) - ) +@Suite struct WingsQuestTests { + @Test("Get bonus points") + func testTaskBonusPoints() { + #expect(bonusPoints(powerUpActive: true, touchingEagle: true)) } - func testNoBonusPointsWhenNotPowerUpActive() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - bonusPoints(powerUpActive: false, touchingEagle: true) - ) + @Test("No bonus points when not power up active", .enabled(if: RUNALL)) + func testNoBonusPointsWhenNotPowerUpActive() { + #expect(!bonusPoints(powerUpActive: false, touchingEagle: true)) } - func testNoBonusPointsWhenNotTouchingOtherBird() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - bonusPoints(powerUpActive: true, touchingEagle: false) - ) + @Test("No bonus points when not touching other bird", .enabled(if: RUNALL)) + func testNoBonusPointsWhenNotTouchingOtherBird() { + #expect(!bonusPoints(powerUpActive: true, touchingEagle: false)) } - func testNoBonusPointsWhenNotTouchingOtherBirdnorPowerUp() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - bonusPoints(powerUpActive: false, touchingEagle: false) - ) + @Test("No bonus points when not touching other bird nor power up", .enabled(if: RUNALL)) + func testNoBonusPointsWhenNotTouchingOtherBirdnorPowerUp() { + #expect(!bonusPoints(powerUpActive: false, touchingEagle: false)) } -} -class TaskScore: XCTestCase { - func testGetScore() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue( - score(touchingPowerUp: true, touchingSeed: true) - ) + @Test("Get score", .enabled(if: RUNALL)) + func testTaskScore() { + #expect(score(touchingPowerUp: true, touchingSeed: true)) } - func testGetScoreWhenNotTouchingSeed() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue( - score(touchingPowerUp: false, touchingSeed: true) - ) + @Test("Get score when not touching seed", .enabled(if: RUNALL)) + func testGetScoreWhenNotTouchingSeed() { + #expect(score(touchingPowerUp: false, touchingSeed: true)) } - func testGetScoreWhenNotTouchingPowerUp() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue( - score(touchingPowerUp: true, touchingSeed: false) - ) + @Test("Get score when not touching power up", .enabled(if: RUNALL)) + func testGetScoreWhenNotTouchingPowerUp() { + #expect(score(touchingPowerUp: true, touchingSeed: false)) } - func testNoScoreWhenBothIsFalse() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - score(touchingPowerUp: false, touchingSeed: false) - ) + @Test("No score when both is false", .enabled(if: RUNALL)) + func testNoScoreWhenBothIsFalse() { + #expect(!score(touchingPowerUp: false, touchingSeed: false)) } -} -class TaskLose: XCTestCase { - func testLose() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue( - lose(powerUpActive: false, touchingEagle: true) - ) + @Test("Lose", .enabled(if: RUNALL)) + func testTaskLose() { + #expect(lose(powerUpActive: false, touchingEagle: true)) } - func testDontLoseWhenPowerUp() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - lose(powerUpActive: true, touchingEagle: true) - ) + @Test("Don't lose when power up", .enabled(if: RUNALL)) + func testDontLoseWhenPowerUp() { + #expect(!lose(powerUpActive: true, touchingEagle: true)) } - func testDontLoseWhenNotTouchingAndPowerUp() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - lose(powerUpActive: false, touchingEagle: false) - ) + @Test("Don't lose when not touching and power up", .enabled(if: RUNALL)) + func testDontLoseWhenNotTouchingAndPowerUp() { + #expect(!lose(powerUpActive: false, touchingEagle: false)) } - func testDontLoseWhenNotTouching() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - lose(powerUpActive: true, touchingEagle: false) - ) + @Test("Don't lose when not touching", .enabled(if: RUNALL)) + func testDontLoseWhenNotTouching() { + #expect(!lose(powerUpActive: true, touchingEagle: false)) } -} -class TaskWin: XCTestCase { - func testWin() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue( - win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: false) - ) + @Test("Win", .enabled(if: RUNALL)) + func testTaskWin() { + #expect(win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: false)) } - func testDontWinIfLost() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: true) - ) + @Test("Don't win if lost", .enabled(if: RUNALL)) + func testDontWinIfLost() { + #expect(!win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: true)) } - func testWinIfPickedUpAllSeedsAndTouchingOtherBird() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse( - win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: true) - ) + @Test("Win if picked up all seeds and touching other bird", .enabled(if: RUNALL)) + func testWinIfPickedUpAllSeedsAndTouchingOtherBird() { + #expect(!win(hasPickedUpAllSeeds: true, powerUpActive: false, touchingEagle: true)) } }