diff --git a/exercises/practice/pascals-triangle/.meta/template.swift b/exercises/practice/pascals-triangle/.meta/template.swift index 1e31fffd1..4365daedb 100644 --- a/exercises/practice/pascals-triangle/.meta/template.swift +++ b/exercises/practice/pascals-triangle/.meta/template.swift @@ -1,16 +1,18 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} - XCTAssertEqual(pascalsTriangle(rows: {{case.input | extractCountKey}}), {{case.expected}}) + func test{{case.description |camelCase }}() { + #expect(pascalsTriangle(rows: {{case.input | extractCountKey}}) == {{case.expected}}) } {% endfor -%} } diff --git a/exercises/practice/pascals-triangle/Package.swift b/exercises/practice/pascals-triangle/Package.swift index 831e5dddb..0198fb031 100644 --- a/exercises/practice/pascals-triangle/Package.swift +++ b/exercises/practice/pascals-triangle/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift b/exercises/practice/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift index 317d93fe3..e6ca50264 100644 --- a/exercises/practice/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift +++ b/exercises/practice/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift @@ -1,52 +1,55 @@ -import XCTest +import Foundation +import Testing @testable import PascalsTriangle -class PascalsTriangleTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PascalsTriangleTests { + + @Test("zero rows") func testZeroRows() { - XCTAssertEqual(pascalsTriangle(rows: 0), []) + #expect(pascalsTriangle(rows: 0) == []) } - func testSingleRow() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(pascalsTriangle(rows: 1), [[1]]) + @Test("single row", .enabled(if: RUNALL)) + func testSingleRow() { + #expect(pascalsTriangle(rows: 1) == [[1]]) } - func testTwoRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(pascalsTriangle(rows: 2), [[1], [1, 1]]) + @Test("two rows", .enabled(if: RUNALL)) + func testTwoRows() { + #expect(pascalsTriangle(rows: 2) == [[1], [1, 1]]) } - func testThreeRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(pascalsTriangle(rows: 3), [[1], [1, 1], [1, 2, 1]]) + @Test("three rows", .enabled(if: RUNALL)) + func testThreeRows() { + #expect(pascalsTriangle(rows: 3) == [[1], [1, 1], [1, 2, 1]]) } - func testFourRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(pascalsTriangle(rows: 4), [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]) + @Test("four rows", .enabled(if: RUNALL)) + func testFourRows() { + #expect(pascalsTriangle(rows: 4) == [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]) } - func testFiveRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - pascalsTriangle(rows: 5), [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]) + @Test("five rows", .enabled(if: RUNALL)) + func testFiveRows() { + #expect( + pascalsTriangle(rows: 5) == [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]) } - func testSixRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - pascalsTriangle(rows: 6), - [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]]) + @Test("six rows", .enabled(if: RUNALL)) + func testSixRows() { + #expect( + pascalsTriangle(rows: 6) == [ + [1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], + ]) } - func testTenRows() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - pascalsTriangle(rows: 10), - [ + @Test("ten rows", .enabled(if: RUNALL)) + func testTenRows() { + #expect( + pascalsTriangle(rows: 10) == [ [1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84, 36, 9, 1], diff --git a/exercises/practice/perfect-numbers/.meta/template.swift b/exercises/practice/perfect-numbers/.meta/template.swift index e7b3a22cc..b3ec52c0e 100644 --- a/exercises/practice/perfect-numbers/.meta/template.swift +++ b/exercises/practice/perfect-numbers/.meta/template.swift @@ -1,21 +1,23 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% outer: for case in cases %} {%- for subCases in case.cases %} {%- if forloop.outer.first and forloop.first %} - func test{{subCases.description |camelCase }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{subCases.description}}", .enabled(if: RUNALL)) {%- endif %} + func test{{subCases.description |camelCase }}() { {%- ifnot subCases.expected.error %} - XCTAssertEqual(try! classify(number: {{subCases.input.number}}), .{{subCases.expected}}) + #expect(try! classify(number: {{subCases.input.number}}) == .{{subCases.expected}}) {%- else %} - XCTAssertThrowsError(try classify(number: {{subCases.input.number}})) { error in - XCTAssertEqual(error as? ClassificationError, .invalidInput) + #expect(throws: ClassificationError.invalidInput) { + try classify(number: {{subCases.input.number}}) } {%- endif %} } diff --git a/exercises/practice/perfect-numbers/Package.swift b/exercises/practice/perfect-numbers/Package.swift index 65507c5f6..062be0173 100644 --- a/exercises/practice/perfect-numbers/Package.swift +++ b/exercises/practice/perfect-numbers/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/perfect-numbers/Tests/PerfectNumbersTests/PerfectNumbersTests.swift b/exercises/practice/perfect-numbers/Tests/PerfectNumbersTests/PerfectNumbersTests.swift index 5ee384685..2e37184d9 100644 --- a/exercises/practice/perfect-numbers/Tests/PerfectNumbersTests/PerfectNumbersTests.swift +++ b/exercises/practice/perfect-numbers/Tests/PerfectNumbersTests/PerfectNumbersTests.swift @@ -1,75 +1,78 @@ -import XCTest +import Foundation +import Testing @testable import PerfectNumbers -class PerfectNumbersTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PerfectNumbersTests { + + @Test("Smallest perfect number is classified correctly") func testSmallestPerfectNumberIsClassifiedCorrectly() { - XCTAssertEqual(try! classify(number: 6), .perfect) + #expect(try! classify(number: 6) == .perfect) } - func testMediumPerfectNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 28), .perfect) + @Test("Medium perfect number is classified correctly", .enabled(if: RUNALL)) + func testMediumPerfectNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 28) == .perfect) } - func testLargePerfectNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 33_550_336), .perfect) + @Test("Large perfect number is classified correctly", .enabled(if: RUNALL)) + func testLargePerfectNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 33_550_336) == .perfect) } - func testSmallestAbundantNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 12), .abundant) + @Test("Smallest abundant number is classified correctly", .enabled(if: RUNALL)) + func testSmallestAbundantNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 12) == .abundant) } - func testMediumAbundantNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 30), .abundant) + @Test("Medium abundant number is classified correctly", .enabled(if: RUNALL)) + func testMediumAbundantNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 30) == .abundant) } - func testLargeAbundantNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 33_550_335), .abundant) + @Test("Large abundant number is classified correctly", .enabled(if: RUNALL)) + func testLargeAbundantNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 33_550_335) == .abundant) } - func testSmallestPrimeDeficientNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 2), .deficient) + @Test("Smallest prime deficient number is classified correctly", .enabled(if: RUNALL)) + func testSmallestPrimeDeficientNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 2) == .deficient) } - func testSmallestNonPrimeDeficientNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 4), .deficient) + @Test("Smallest non-prime deficient number is classified correctly", .enabled(if: RUNALL)) + func testSmallestNonPrimeDeficientNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 4) == .deficient) } - func testMediumDeficientNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 32), .deficient) + @Test("Medium deficient number is classified correctly", .enabled(if: RUNALL)) + func testMediumDeficientNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 32) == .deficient) } - func testLargeDeficientNumberIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 33_550_337), .deficient) + @Test("Large deficient number is classified correctly", .enabled(if: RUNALL)) + func testLargeDeficientNumberIsClassifiedCorrectly() { + #expect(try! classify(number: 33_550_337) == .deficient) } - func testEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! classify(number: 1), .deficient) + @Test("Edge case (no factors other than itself) is classified correctly", .enabled(if: RUNALL)) + func testEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly() { + #expect(try! classify(number: 1) == .deficient) } - func testZeroIsRejectedAsItIsNotAPositiveInteger() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try classify(number: 0)) { error in - XCTAssertEqual(error as? ClassificationError, .invalidInput) + @Test("Zero is rejected (as it is not a positive integer)", .enabled(if: RUNALL)) + func testZeroIsRejectedAsItIsNotAPositiveInteger() { + #expect(throws: ClassificationError.invalidInput) { + try classify(number: 0) } } - func testNegativeIntegerIsRejectedAsItIsNotAPositiveInteger() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try classify(number: -1)) { error in - XCTAssertEqual(error as? ClassificationError, .invalidInput) + @Test("Negative integer is rejected (as it is not a positive integer)", .enabled(if: RUNALL)) + func testNegativeIntegerIsRejectedAsItIsNotAPositiveInteger() { + #expect(throws: ClassificationError.invalidInput) { + try classify(number: -1) } } } diff --git a/exercises/practice/phone-number/.meta/template.swift b/exercises/practice/phone-number/.meta/template.swift index 3ab6fc538..a04071e91 100644 --- a/exercises/practice/phone-number/.meta/template.swift +++ b/exercises/practice/phone-number/.meta/template.swift @@ -1,21 +1,23 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} + func test{{case.description |camelCase }}() { {% if case.expected.error -%} - XCTAssertThrowsError(try PhoneNumber("{{case.input.phrase}}").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("{{case.input.phrase}}").clean() } {% else -%} - XCTAssertEqual(try! PhoneNumber("{{case.input.phrase}}").clean(), "{{case.expected}}") + #expect(try! PhoneNumber("{{case.input.phrase}}").clean() == "{{case.expected}}") {% endif -%} } {% endfor -%} diff --git a/exercises/practice/phone-number/Package.swift b/exercises/practice/phone-number/Package.swift index 94c78392c..2d5236937 100644 --- a/exercises/practice/phone-number/Package.swift +++ b/exercises/practice/phone-number/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/phone-number/Tests/PhoneNumberTests/PhoneNumberTests.swift b/exercises/practice/phone-number/Tests/PhoneNumberTests/PhoneNumberTests.swift index 22199e2b5..8f5a34b5d 100644 --- a/exercises/practice/phone-number/Tests/PhoneNumberTests/PhoneNumberTests.swift +++ b/exercises/practice/phone-number/Tests/PhoneNumberTests/PhoneNumberTests.swift @@ -1,122 +1,125 @@ -import XCTest +import Foundation +import Testing @testable import PhoneNumber -class PhoneNumberTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PhoneNumberTests { + + @Test("cleans the number") func testCleansTheNumber() { - XCTAssertEqual(try! PhoneNumber("(223) 456-7890").clean(), "2234567890") + #expect(try! PhoneNumber("(223) 456-7890").clean() == "2234567890") } - func testCleansNumbersWithDots() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! PhoneNumber("223.456.7890").clean(), "2234567890") + @Test("cleans numbers with dots", .enabled(if: RUNALL)) + func testCleansNumbersWithDots() { + #expect(try! PhoneNumber("223.456.7890").clean() == "2234567890") } - func testCleansNumbersWithMultipleSpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! PhoneNumber("223 456 7890 ").clean(), "2234567890") + @Test("cleans numbers with multiple spaces", .enabled(if: RUNALL)) + func testCleansNumbersWithMultipleSpaces() { + #expect(try! PhoneNumber("223 456 7890 ").clean() == "2234567890") } - func testInvalidWhen9Digits() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("123456789").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid when 9 digits", .enabled(if: RUNALL)) + func testInvalidWhen9Digits() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("123456789").clean() } } - func testInvalidWhen11DigitsDoesNotStartWithA1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("22234567890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid when 11 digits does not start with a 1", .enabled(if: RUNALL)) + func testInvalidWhen11DigitsDoesNotStartWithA1() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("22234567890").clean() } } - func testValidWhen11DigitsAndStartingWith1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! PhoneNumber("12234567890").clean(), "2234567890") + @Test("valid when 11 digits and starting with 1", .enabled(if: RUNALL)) + func testValidWhen11DigitsAndStartingWith1() { + #expect(try! PhoneNumber("12234567890").clean() == "2234567890") } - func testValidWhen11DigitsAndStartingWith1EvenWithPunctuation() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! PhoneNumber("+1 (223) 456-7890").clean(), "2234567890") + @Test("valid when 11 digits and starting with 1 even with punctuation", .enabled(if: RUNALL)) + func testValidWhen11DigitsAndStartingWith1EvenWithPunctuation() { + #expect(try! PhoneNumber("+1 (223) 456-7890").clean() == "2234567890") } - func testInvalidWhenMoreThan11Digits() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("321234567890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid when more than 11 digits", .enabled(if: RUNALL)) + func testInvalidWhenMoreThan11Digits() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("321234567890").clean() } } - func testInvalidWithLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("523-abc-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid with letters", .enabled(if: RUNALL)) + func testInvalidWithLetters() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("523-abc-7890").clean() } } - func testInvalidWithPunctuations() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("523-@:!-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid with punctuations", .enabled(if: RUNALL)) + func testInvalidWithPunctuations() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("523-@:!-7890").clean() } } - func testInvalidIfAreaCodeStartsWith0() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("(023) 456-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if area code starts with 0", .enabled(if: RUNALL)) + func testInvalidIfAreaCodeStartsWith0() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("(023) 456-7890").clean() } } - func testInvalidIfAreaCodeStartsWith1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("(123) 456-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if area code starts with 1", .enabled(if: RUNALL)) + func testInvalidIfAreaCodeStartsWith1() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("(123) 456-7890").clean() } } - func testInvalidIfExchangeCodeStartsWith0() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("(223) 056-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if exchange code starts with 0", .enabled(if: RUNALL)) + func testInvalidIfExchangeCodeStartsWith0() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("(223) 056-7890").clean() } } - func testInvalidIfExchangeCodeStartsWith1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("(223) 156-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if exchange code starts with 1", .enabled(if: RUNALL)) + func testInvalidIfExchangeCodeStartsWith1() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("(223) 156-7890").clean() } } - func testInvalidIfAreaCodeStartsWith0OnValid11DigitNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("1 (023) 456-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if area code starts with 0 on valid 11-digit number", .enabled(if: RUNALL)) + func testInvalidIfAreaCodeStartsWith0OnValid11DigitNumber() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("1 (023) 456-7890").clean() } } - func testInvalidIfAreaCodeStartsWith1OnValid11DigitNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("1 (123) 456-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if area code starts with 1 on valid 11-digit number", .enabled(if: RUNALL)) + func testInvalidIfAreaCodeStartsWith1OnValid11DigitNumber() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("1 (123) 456-7890").clean() } } - func testInvalidIfExchangeCodeStartsWith0OnValid11DigitNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("1 (223) 056-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if exchange code starts with 0 on valid 11-digit number", .enabled(if: RUNALL)) + func testInvalidIfExchangeCodeStartsWith0OnValid11DigitNumber() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("1 (223) 056-7890").clean() } } - func testInvalidIfExchangeCodeStartsWith1OnValid11DigitNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PhoneNumber("1 (223) 156-7890").clean()) { - XCTAssertEqual($0 as? PhoneNumberError, .invalidPhoneNumber) + @Test("invalid if exchange code starts with 1 on valid 11-digit number", .enabled(if: RUNALL)) + func testInvalidIfExchangeCodeStartsWith1OnValid11DigitNumber() { + #expect(throws: PhoneNumberError.invalidPhoneNumber) { + try PhoneNumber("1 (223) 156-7890").clean() } } } diff --git a/exercises/practice/pig-latin/.meta/template.swift b/exercises/practice/pig-latin/.meta/template.swift index 067afda9c..bc6c6e682 100644 --- a/exercises/practice/pig-latin/.meta/template.swift +++ b/exercises/practice/pig-latin/.meta/template.swift @@ -1,17 +1,19 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% outer: for case in cases %} {%- for subCases in case.cases %} {%- if forloop.outer.first and forloop.first %} - func test{{subCases.description |camelCase }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{subCases.description}}", .enabled(if: RUNALL)) {%- endif %} - XCTAssertEqual(PigLatin.translate("{{subCases.input.phrase}}"), "{{subCases.expected}}") + func test{{subCases.description |camelCase }}() { + #expect(PigLatin.translate("{{subCases.input.phrase}}") == "{{subCases.expected}}") } {% endfor -%} {% endfor -%} diff --git a/exercises/practice/pig-latin/.meta/tests.toml b/exercises/practice/pig-latin/.meta/tests.toml index c29168c5e..d524305b4 100644 --- a/exercises/practice/pig-latin/.meta/tests.toml +++ b/exercises/practice/pig-latin/.meta/tests.toml @@ -39,6 +39,9 @@ description = "first letter and ay are moved to the end of words that start with [bce94a7a-a94e-4e2b-80f4-b2bb02e40f71] description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with q without a following u" +[e59dbbe8-ccee-4619-a8e9-ce017489bfc0] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with consonant and vowel containing qu" + [c01e049a-e3e2-451c-bf8e-e2abb7e438b8] description = "some letter clusters are treated like a single consonant -> word beginning with ch" diff --git a/exercises/practice/pig-latin/Package.swift b/exercises/practice/pig-latin/Package.swift index e182a4b3c..558e2c938 100644 --- a/exercises/practice/pig-latin/Package.swift +++ b/exercises/practice/pig-latin/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/pig-latin/Tests/PigLatinTests/PigLatinTests.swift b/exercises/practice/pig-latin/Tests/PigLatinTests/PigLatinTests.swift index a13f2a57a..e4347349b 100644 --- a/exercises/practice/pig-latin/Tests/PigLatinTests/PigLatinTests.swift +++ b/exercises/practice/pig-latin/Tests/PigLatinTests/PigLatinTests.swift @@ -1,116 +1,124 @@ -import XCTest +import Foundation +import Testing @testable import PigLatin -class PigLatinTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PigLatinTests { + + @Test("word beginning with a") func testWordBeginningWithA() { - XCTAssertEqual(PigLatin.translate("apple"), "appleay") + #expect(PigLatin.translate("apple") == "appleay") + } + + @Test("word beginning with e", .enabled(if: RUNALL)) + func testWordBeginningWithE() { + #expect(PigLatin.translate("ear") == "earay") } - func testWordBeginningWithE() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("ear"), "earay") + @Test("word beginning with i", .enabled(if: RUNALL)) + func testWordBeginningWithI() { + #expect(PigLatin.translate("igloo") == "iglooay") } - func testWordBeginningWithI() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("igloo"), "iglooay") + @Test("word beginning with o", .enabled(if: RUNALL)) + func testWordBeginningWithO() { + #expect(PigLatin.translate("object") == "objectay") } - func testWordBeginningWithO() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("object"), "objectay") + @Test("word beginning with u", .enabled(if: RUNALL)) + func testWordBeginningWithU() { + #expect(PigLatin.translate("under") == "underay") } - func testWordBeginningWithU() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("under"), "underay") + @Test("word beginning with a vowel and followed by a qu", .enabled(if: RUNALL)) + func testWordBeginningWithAVowelAndFollowedByAQu() { + #expect(PigLatin.translate("equal") == "equalay") } - func testWordBeginningWithAVowelAndFollowedByAQu() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("equal"), "equalay") + @Test("word beginning with p", .enabled(if: RUNALL)) + func testWordBeginningWithP() { + #expect(PigLatin.translate("pig") == "igpay") } - func testWordBeginningWithP() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("pig"), "igpay") + @Test("word beginning with k", .enabled(if: RUNALL)) + func testWordBeginningWithK() { + #expect(PigLatin.translate("koala") == "oalakay") } - func testWordBeginningWithK() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("koala"), "oalakay") + @Test("word beginning with x", .enabled(if: RUNALL)) + func testWordBeginningWithX() { + #expect(PigLatin.translate("xenon") == "enonxay") } - func testWordBeginningWithX() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("xenon"), "enonxay") + @Test("word beginning with q without a following u", .enabled(if: RUNALL)) + func testWordBeginningWithQWithoutAFollowingU() { + #expect(PigLatin.translate("qat") == "atqay") } - func testWordBeginningWithQWithoutAFollowingU() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("qat"), "atqay") + @Test("word beginning with consonant and vowel containing qu", .enabled(if: RUNALL)) + func testWordBeginningWithConsonantAndVowelContainingQu() { + #expect(PigLatin.translate("liquid") == "iquidlay") } - func testWordBeginningWithCh() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("chair"), "airchay") + @Test("word beginning with ch", .enabled(if: RUNALL)) + func testWordBeginningWithCh() { + #expect(PigLatin.translate("chair") == "airchay") } - func testWordBeginningWithQu() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("queen"), "eenquay") + @Test("word beginning with qu", .enabled(if: RUNALL)) + func testWordBeginningWithQu() { + #expect(PigLatin.translate("queen") == "eenquay") } - func testWordBeginningWithQuAndAPrecedingConsonant() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("square"), "aresquay") + @Test("word beginning with qu and a preceding consonant", .enabled(if: RUNALL)) + func testWordBeginningWithQuAndAPrecedingConsonant() { + #expect(PigLatin.translate("square") == "aresquay") } - func testWordBeginningWithTh() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("therapy"), "erapythay") + @Test("word beginning with th", .enabled(if: RUNALL)) + func testWordBeginningWithTh() { + #expect(PigLatin.translate("therapy") == "erapythay") } - func testWordBeginningWithThr() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("thrush"), "ushthray") + @Test("word beginning with thr", .enabled(if: RUNALL)) + func testWordBeginningWithThr() { + #expect(PigLatin.translate("thrush") == "ushthray") } - func testWordBeginningWithSch() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("school"), "oolschay") + @Test("word beginning with sch", .enabled(if: RUNALL)) + func testWordBeginningWithSch() { + #expect(PigLatin.translate("school") == "oolschay") } - func testWordBeginningWithYt() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("yttria"), "yttriaay") + @Test("word beginning with yt", .enabled(if: RUNALL)) + func testWordBeginningWithYt() { + #expect(PigLatin.translate("yttria") == "yttriaay") } - func testWordBeginningWithXr() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("xray"), "xrayay") + @Test("word beginning with xr", .enabled(if: RUNALL)) + func testWordBeginningWithXr() { + #expect(PigLatin.translate("xray") == "xrayay") } - func testYIsTreatedLikeAConsonantAtTheBeginningOfAWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("yellow"), "ellowyay") + @Test("y is treated like a consonant at the beginning of a word", .enabled(if: RUNALL)) + func testYIsTreatedLikeAConsonantAtTheBeginningOfAWord() { + #expect(PigLatin.translate("yellow") == "ellowyay") } - func testYIsTreatedLikeAVowelAtTheEndOfAConsonantCluster() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("rhythm"), "ythmrhay") + @Test("y is treated like a vowel at the end of a consonant cluster", .enabled(if: RUNALL)) + func testYIsTreatedLikeAVowelAtTheEndOfAConsonantCluster() { + #expect(PigLatin.translate("rhythm") == "ythmrhay") } - func testYAsSecondLetterInTwoLetterWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("my"), "ymay") + @Test("y as second letter in two letter word", .enabled(if: RUNALL)) + func testYAsSecondLetterInTwoLetterWord() { + #expect(PigLatin.translate("my") == "ymay") } - func testAWholePhrase() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(PigLatin.translate("quick fast run"), "ickquay astfay unray") + @Test("a whole phrase", .enabled(if: RUNALL)) + func testAWholePhrase() { + #expect(PigLatin.translate("quick fast run") == "ickquay astfay unray") } }