From dc10064695e808450633efb096581bd4a6a60a82 Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 28 Dec 2024 20:57:39 +0100 Subject: [PATCH] Update Swift tools version to 6.0 and refactor tests to use new testing framework --- exercises/concept/custom-signs/Package.swift | 2 +- .../CustomSignsTests/CustomSignsTests.swift | 92 ++++++------- .../concept/vehicle-purchase/Package.swift | 2 +- .../VehiclePurchaseTests.swift | 126 ++++++++---------- 4 files changed, 98 insertions(+), 124 deletions(-) diff --git a/exercises/concept/custom-signs/Package.swift b/exercises/concept/custom-signs/Package.swift index 511a42494..9a0482dc0 100644 --- a/exercises/concept/custom-signs/Package.swift +++ b/exercises/concept/custom-signs/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/custom-signs/Tests/CustomSignsTests/CustomSignsTests.swift b/exercises/concept/custom-signs/Tests/CustomSignsTests/CustomSignsTests.swift index f3e98bf63..d5ba5eb0f 100644 --- a/exercises/concept/custom-signs/Tests/CustomSignsTests/CustomSignsTests.swift +++ b/exercises/concept/custom-signs/Tests/CustomSignsTests/CustomSignsTests.swift @@ -1,81 +1,73 @@ -import XCTest +import Testing +import Foundation @testable import CustomSigns -let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false -class TaskStringConstants: XCTestCase { +@Suite struct CustomSignsTest { + @Test("Test Birthday") func testBirthday() { - XCTAssertEqual(birthday, "Birthday") + #expect(birthday == "Birthday") } - func testValentine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(valentine, "Valentine's Day") + @Test("Test Valentine", .enabled(if: RUNALL)) + func testValentine() { + #expect(valentine == "Valentine's Day") } - func testAnniversary() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(anniversary, "Anniversary") + @Test("Test Anniversary", .enabled(if: RUNALL)) + func testAnniversary() { + #expect(anniversary == "Anniversary") } -} -class TaskCharacterConstants: XCTestCase { - func testSpace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(space, " " as Character) + @Test("Test Space", .enabled(if: RUNALL)) + func testSpace() { + #expect(space == " " as Character) } - func testExclamation() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(exclamation, "!" as Character) + @Test("Test Exclamation", .enabled(if: RUNALL)) + func testExclamation() { + #expect(exclamation == "!" as Character) } -} -class TaskBuildSign: XCTestCase { - func testBuildSign() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(buildSign(for: valentine, name: "Hikaru"), "Happy Valentine's Day Hikaru!") + @Test("Test Build Sign", .enabled(if: RUNALL)) + func testBuildSign() { + #expect(buildSign(for: valentine, name: "Hikaru") == "Happy Valentine's Day Hikaru!") } - func testBuildSignNoName() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(buildSign(for: birthday, name: ""), "Happy Birthday !") + @Test("Test Build Sign with No Name", .enabled(if: RUNALL)) + func testBuildSignNoName() { + #expect(buildSign(for: birthday, name: "") == "Happy Birthday !") } - func testBuildSignAnniversary() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(buildSign(for: anniversary, name: "Bob"), "Happy Anniversary Bob!") + @Test("Test Build Sign Anniversary", .enabled(if: RUNALL)) + func testBuildSignAnniversary() { + #expect(buildSign(for: anniversary, name: "Bob") == "Happy Anniversary Bob!") } -} -class TaskGraduationFor: XCTestCase { - func testGraduation() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - graduationFor(name: "Isabel", year: 1988), "Congratulations Isabel!\nClass of 1988") + @Test("Test Graduation For", .enabled(if: RUNALL)) + func testGraduationFor() { + #expect(graduationFor(name: "Isabel", year: 1988) == "Congratulations Isabel!\nClass of 1988") } - func testGraduation2005() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - graduationFor(name: "Jeremy", year: 2005), "Congratulations Jeremy!\nClass of 2005") + @Test("Test Graduation For 2005", .enabled(if: RUNALL)) + func testGraduation2005() { + #expect(graduationFor(name: "Jeremy", year: 2005) == "Congratulations Jeremy!\nClass of 2005") } -} -class TaskCostOf: XCTestCase { - func testCostOfSign() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(costOf(sign: graduationFor(name: "Isabel", year: 1988)), 94) + @Test("Test Cost Of Sign", .enabled(if: RUNALL)) + func testCostOfSign() { + #expect(costOf(sign: graduationFor(name: "Isabel", year: 1988)) == 94) } - func testBuiltSign() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(costOf(sign: buildSign(for: anniversary, name: "Bob")), 64) + @Test("Test Built Sign", .enabled(if: RUNALL)) + func testBuiltSign() { + #expect(costOf(sign: buildSign(for: anniversary, name: "Bob")) == 64) } - func testCostOfSignEmpty() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(costOf(sign: ""), 20) + @Test("Test Cost Of Sign Empty", .enabled(if: RUNALL)) + func testCostOfSignEmpty() { + #expect(costOf(sign: "") == 20) } } diff --git a/exercises/concept/vehicle-purchase/Package.swift b/exercises/concept/vehicle-purchase/Package.swift index c24cabd59..6853e5280 100644 --- a/exercises/concept/vehicle-purchase/Package.swift +++ b/exercises/concept/vehicle-purchase/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/vehicle-purchase/Tests/VehiclePurchaseTests/VehiclePurchaseTests.swift b/exercises/concept/vehicle-purchase/Tests/VehiclePurchaseTests/VehiclePurchaseTests.swift index 82fe12d59..80bf89b12 100644 --- a/exercises/concept/vehicle-purchase/Tests/VehiclePurchaseTests/VehiclePurchaseTests.swift +++ b/exercises/concept/vehicle-purchase/Tests/VehiclePurchaseTests/VehiclePurchaseTests.swift @@ -1,111 +1,93 @@ -import XCTest +import Testing +import Foundation @testable import VehiclePurchase -let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false -class TaskCanIBuy: XCTestCase { +@Suite struct VehiclePurchaseTests { + @Test("Test if a vehicle can be bought") func testCanBuy() { - XCTAssertEqual( - canIBuy(vehicle: "1974 Ford Pinto", price: 516.32, monthlyBudget: 100.00), - "Yes! I'm getting a 1974 Ford Pinto") + #expect(canIBuy(vehicle: "1974 Ford Pinto", price: 516.32, monthlyBudget: 100.00) == "Yes! I'm getting a 1974 Ford Pinto") } - func testCannotBuy() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - canIBuy(vehicle: "2011 Bugatti Veyron", price: 2_250_880.00, monthlyBudget: 10000.00), - "Darn! No 2011 Bugatti Veyron for me") + @Test("Test if a vehicle cannot be bought", .enabled(if: RUNALL)) + func testCannotBuy() { + #expect(canIBuy(vehicle: "2011 Bugatti Veyron", price: 2_250_880.00, monthlyBudget: 10000.00) == "Darn! No 2011 Bugatti Veyron for me") } - func testBeFrugal() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - canIBuy(vehicle: "2020 Indian FTR 1200", price: 12_500, monthlyBudget: 200), - "I'll have to be frugal if I want a 2020 Indian FTR 1200") + @Test("Test if a vehicle can be bought with frugality", .enabled(if: RUNALL)) + func testBeFrugal() { + #expect(canIBuy(vehicle: "2020 Indian FTR 1200", price: 12_500, monthlyBudget: 200) == "I'll have to be frugal if I want a 2020 Indian FTR 1200") } -} -class TaskLicenseType: XCTestCase { - func testTwoWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 2), "You will need a motorcycle license for your vehicle") + @Test("Test what license is needed for two wheels", .enabled(if: RUNALL)) + func testTwoWheels() { + #expect(licenseType(numberOfWheels: 2) == "You will need a motorcycle license for your vehicle") } - func testThreeWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 3), "You will need a motorcycle license for your vehicle") + @Test("Test what license is needed for three wheels", .enabled(if: RUNALL)) + func testThreeWheels() { + #expect(licenseType(numberOfWheels: 3) == "You will need a motorcycle license for your vehicle") } - func testFourWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 4), "You will need an automobile license for your vehicle") + @Test("Test what license is needed for four wheels", .enabled(if: RUNALL)) + func testFourWheels() { + #expect(licenseType(numberOfWheels: 4) == "You will need an automobile license for your vehicle") } - func testFiveWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 5), "We do not issue licenses for those types of vehicles") + @Test("Test what license is needed for five wheels", .enabled(if: RUNALL)) + func testFiveWheels() { + #expect(licenseType(numberOfWheels: 5) == "We do not issue licenses for those types of vehicles") } - func testSixWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 6), "You will need an automobile license for your vehicle") + @Test("Test what license is needed for six wheels", .enabled(if: RUNALL)) + func testSixWheels() { + #expect(licenseType(numberOfWheels: 6) == "You will need an automobile license for your vehicle") } - func testSevenWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 7), "We do not issue licenses for those types of vehicles") + @Test("Test what license is needed for seven wheels", .enabled(if: RUNALL)) + func testSevenWheels() { + #expect(licenseType(numberOfWheels: 7) == "We do not issue licenses for those types of vehicles") } - func testEighteenWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 18), - "You will need a commercial trucking license for your vehicle") + @Test("Test what license is needed for eighteen wheels", .enabled(if: RUNALL)) + func testEighteenWheels() { + #expect(licenseType(numberOfWheels: 18) == "You will need a commercial trucking license for your vehicle") } - func testZeroWheels() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 0), "We do not issue licenses for those types of vehicles") + @Test("Test what license is needed for zero wheels", .enabled(if: RUNALL)) + func testZeroWheels() { + #expect(licenseType(numberOfWheels: 0) == "We do not issue licenses for those types of vehicles") } - func testOneWheel() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - licenseType(numberOfWheels: 1), "We do not issue licenses for those types of vehicles") + @Test("Test what license is needed for one wheel", .enabled(if: RUNALL)) + func testOneWheel() { + #expect(licenseType(numberOfWheels: 1) == "We do not issue licenses for those types of vehicles") } -} -class TaskCalculateResellPrice: XCTestCase { - func testPriceUnderThreeYears() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(calculateResellPrice(originalPrice: 40_000, yearsOld: 2), 32_000) + @Test("Test the resell price of a vehicle under three years old", .enabled(if: RUNALL)) + func testPriceUnderThreeYears() { + #expect(calculateResellPrice(originalPrice: 40_000, yearsOld: 2) == 32_000) } - func testPriceWhenThreeYears() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(calculateResellPrice(originalPrice: 40_000, yearsOld: 3), 28_000) + @Test("Test the resell price of a vehicle when three years old", .enabled(if: RUNALL)) + func testPriceWhenThreeYears() { + #expect(calculateResellPrice(originalPrice: 40_000, yearsOld: 3) == 28_000) } - func testPriceWhenSevenYears() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(calculateResellPrice(originalPrice: 50_000, yearsOld: 7), 35_000) + @Test("Test the resell price of a vehicle when seven years old", .enabled(if: RUNALL)) + func testPriceWhenSevenYears() { + #expect(calculateResellPrice(originalPrice: 50_000, yearsOld: 7) == 35_000) } - func testPriceWhenTenYears() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(calculateResellPrice(originalPrice: 25_000, yearsOld: 10), 12_500) + @Test("Test the resell price of a vehicle when ten years old", .enabled(if: RUNALL)) + func testPriceWhenTenYears() { + #expect(calculateResellPrice(originalPrice: 25_000, yearsOld: 10) == 12_500) } - func testPriceWhenOverTenYears() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(calculateResellPrice(originalPrice: 50_000, yearsOld: 11), 25_000) + @Test("Test the resell price of a vehicle when over ten years old", .enabled(if: RUNALL)) + func testPriceWhenOverTenYears() { + #expect(calculateResellPrice(originalPrice: 50_000, yearsOld: 11) == 25_000) } }