diff --git a/exercises/practice/diamond/.meta/template.swift b/exercises/practice/diamond/.meta/template.swift index ccf01dc44..7c5187d4a 100644 --- a/exercises/practice/diamond/.meta/template.swift +++ b/exercises/practice/diamond/.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(Diamond.makeDiamond(letter: "{{case.input.letter}}"), {{case.expected | toStringArray}}) + func test{{case.description |camelCase }}() { + #expect(Diamond.makeDiamond(letter: "{{case.input.letter}}") == {{case.expected | toStringArray}}) } {% endfor -%} } diff --git a/exercises/practice/diamond/Package.swift b/exercises/practice/diamond/Package.swift index cb820ca5a..dabe4cb77 100644 --- a/exercises/practice/diamond/Package.swift +++ b/exercises/practice/diamond/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/diamond/Tests/DiamondTests/DiamondTests.swift b/exercises/practice/diamond/Tests/DiamondTests/DiamondTests.swift index 8090fe8ca..25456cede 100644 --- a/exercises/practice/diamond/Tests/DiamondTests/DiamondTests.swift +++ b/exercises/practice/diamond/Tests/DiamondTests/DiamondTests.swift @@ -1,36 +1,39 @@ -import XCTest +import Foundation +import Testing @testable import Diamond -class DiamondTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct DiamondTests { + + @Test("Degenerate case with a single 'A' row") func testDegenerateCaseWithASingleARow() { - XCTAssertEqual(Diamond.makeDiamond(letter: "A"), ["A"]) + #expect(Diamond.makeDiamond(letter: "A") == ["A"]) } - func testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(Diamond.makeDiamond(letter: "B"), [" A ", "B B", " A "]) + @Test("Degenerate case with no row containing 3 distinct groups of spaces", .enabled(if: RUNALL)) + func testDegenerateCaseWithNoRowContaining3DistinctGroupsOfSpaces() { + #expect(Diamond.makeDiamond(letter: "B") == [" A ", "B B", " A "]) } - func testSmallestNonDegenerateCaseWithOddDiamondSideLength() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(Diamond.makeDiamond(letter: "C"), [" A ", " B B ", "C C", " B B ", " A "]) + @Test("Smallest non-degenerate case with odd diamond side length", .enabled(if: RUNALL)) + func testSmallestNonDegenerateCaseWithOddDiamondSideLength() { + #expect(Diamond.makeDiamond(letter: "C") == [" A ", " B B ", "C C", " B B ", " A "]) } - func testSmallestNonDegenerateCaseWithEvenDiamondSideLength() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Diamond.makeDiamond(letter: "D"), - [" A ", " B B ", " C C ", "D D", " C C ", " B B ", " A "]) + @Test("Smallest non-degenerate case with even diamond side length", .enabled(if: RUNALL)) + func testSmallestNonDegenerateCaseWithEvenDiamondSideLength() { + #expect( + Diamond.makeDiamond(letter: "D") == [ + " A ", " B B ", " C C ", "D D", " C C ", " B B ", " A ", + ]) } - func testLargestPossibleDiamond() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Diamond.makeDiamond(letter: "Z"), - [ + @Test("Largest possible diamond", .enabled(if: RUNALL)) + func testLargestPossibleDiamond() { + #expect( + Diamond.makeDiamond(letter: "Z") == [ " A ", " B B ", " C C ", diff --git a/exercises/practice/difference-of-squares/.meta/template.swift b/exercises/practice/difference-of-squares/.meta/template.swift index 62075e892..525e5b88b 100644 --- a/exercises/practice/difference-of-squares/.meta/template.swift +++ b/exercises/practice/difference-of-squares/.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({{subCases.expected}}, Squares({{subCases.input.number}}).{{subCases.property}}) + func test{{subCases.description |camelCase }}() { + #expect({{subCases.expected}} == Squares({{subCases.input.number}}).{{subCases.property}}) } {% endfor -%} {% endfor -%} diff --git a/exercises/practice/difference-of-squares/Package.swift b/exercises/practice/difference-of-squares/Package.swift index 0803a085a..f6e213f6c 100644 --- a/exercises/practice/difference-of-squares/Package.swift +++ b/exercises/practice/difference-of-squares/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/difference-of-squares/Tests/DifferenceOfSquaresTests/DifferenceOfSquaresTests.swift b/exercises/practice/difference-of-squares/Tests/DifferenceOfSquaresTests/DifferenceOfSquaresTests.swift index 6c8068d30..eacdd90a6 100644 --- a/exercises/practice/difference-of-squares/Tests/DifferenceOfSquaresTests/DifferenceOfSquaresTests.swift +++ b/exercises/practice/difference-of-squares/Tests/DifferenceOfSquaresTests/DifferenceOfSquaresTests.swift @@ -1,51 +1,54 @@ -import XCTest +import Foundation +import Testing @testable import DifferenceOfSquares -class DifferenceOfSquaresTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct DifferenceOfSquaresTests { + + @Test("square of sum 1") func testSquareOfSum1() { - XCTAssertEqual(1, Squares(1).squareOfSum) + #expect(1 == Squares(1).squareOfSum) } - func testSquareOfSum5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(225, Squares(5).squareOfSum) + @Test("square of sum 5", .enabled(if: RUNALL)) + func testSquareOfSum5() { + #expect(225 == Squares(5).squareOfSum) } - func testSquareOfSum100() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(25_502_500, Squares(100).squareOfSum) + @Test("square of sum 100", .enabled(if: RUNALL)) + func testSquareOfSum100() { + #expect(25_502_500 == Squares(100).squareOfSum) } - func testSumOfSquares1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(1, Squares(1).sumOfSquares) + @Test("sum of squares 1", .enabled(if: RUNALL)) + func testSumOfSquares1() { + #expect(1 == Squares(1).sumOfSquares) } - func testSumOfSquares5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(55, Squares(5).sumOfSquares) + @Test("sum of squares 5", .enabled(if: RUNALL)) + func testSumOfSquares5() { + #expect(55 == Squares(5).sumOfSquares) } - func testSumOfSquares100() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(338350, Squares(100).sumOfSquares) + @Test("sum of squares 100", .enabled(if: RUNALL)) + func testSumOfSquares100() { + #expect(338350 == Squares(100).sumOfSquares) } - func testDifferenceOfSquares1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(0, Squares(1).differenceOfSquares) + @Test("difference of squares 1", .enabled(if: RUNALL)) + func testDifferenceOfSquares1() { + #expect(0 == Squares(1).differenceOfSquares) } - func testDifferenceOfSquares5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(170, Squares(5).differenceOfSquares) + @Test("difference of squares 5", .enabled(if: RUNALL)) + func testDifferenceOfSquares5() { + #expect(170 == Squares(5).differenceOfSquares) } - func testDifferenceOfSquares100() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(25_164_150, Squares(100).differenceOfSquares) + @Test("difference of squares 100", .enabled(if: RUNALL)) + func testDifferenceOfSquares100() { + #expect(25_164_150 == Squares(100).differenceOfSquares) } } diff --git a/exercises/practice/dominoes/.meta/template.swift b/exercises/practice/dominoes/.meta/template.swift index f2a3c1821..60e18f551 100644 --- a/exercises/practice/dominoes/.meta/template.swift +++ b/exercises/practice/dominoes/.meta/template.swift @@ -1,15 +1,17 @@ -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 }}() { {% ifnot case.input.dominoes -%} let input = [(Int, Int)]() {% else -%} @@ -17,9 +19,9 @@ class {{exercise|camelCase}}Tests: XCTestCase { {% endif -%} {% if case.expected -%} - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) {% else -%} - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) {% endif -%} } {% endfor -%} diff --git a/exercises/practice/dominoes/Package.swift b/exercises/practice/dominoes/Package.swift index 3f18484cf..9d6e66802 100644 --- a/exercises/practice/dominoes/Package.swift +++ b/exercises/practice/dominoes/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/dominoes/Tests/DominoesTests/DominoesTests.swift b/exercises/practice/dominoes/Tests/DominoesTests/DominoesTests.swift index 75c820f3c..75016954e 100644 --- a/exercises/practice/dominoes/Tests/DominoesTests/DominoesTests.swift +++ b/exercises/practice/dominoes/Tests/DominoesTests/DominoesTests.swift @@ -1,84 +1,87 @@ -import XCTest +import Foundation +import Testing @testable import Dominoes -class DominoesTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct DominoesTests { + + @Test("empty input = empty output") func testEmptyInputEmptyOutput() { let input = [(Int, Int)]() - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testSingletonInputSingletonOutput() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("singleton input = singleton output", .enabled(if: RUNALL)) + func testSingletonInputSingletonOutput() { let input = [(1, 1)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testSingletonThatCantBeChained() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("singleton that can't be chained", .enabled(if: RUNALL)) + func testSingletonThatCantBeChained() { let input = [(1, 2)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } - func testThreeElements() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("three elements", .enabled(if: RUNALL)) + func testThreeElements() { let input = [(1, 2), (3, 1), (2, 3)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testCanReverseDominoes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("can reverse dominoes", .enabled(if: RUNALL)) + func testCanReverseDominoes() { let input = [(1, 2), (1, 3), (2, 3)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testCantBeChained() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("can't be chained", .enabled(if: RUNALL)) + func testCantBeChained() { let input = [(1, 2), (4, 1), (2, 3)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } - func testDisconnectedSimple() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("disconnected - simple", .enabled(if: RUNALL)) + func testDisconnectedSimple() { let input = [(1, 1), (2, 2)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } - func testDisconnectedDoubleLoop() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("disconnected - double loop", .enabled(if: RUNALL)) + func testDisconnectedDoubleLoop() { let input = [(1, 2), (2, 1), (3, 4), (4, 3)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } - func testDisconnectedSingleIsolated() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("disconnected - single isolated", .enabled(if: RUNALL)) + func testDisconnectedSingleIsolated() { let input = [(1, 2), (2, 3), (3, 1), (4, 4)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } - func testNeedBacktrack() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("need backtrack", .enabled(if: RUNALL)) + func testNeedBacktrack() { let input = [(1, 2), (2, 3), (3, 1), (2, 4), (2, 4)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testSeparateLoops() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("separate loops", .enabled(if: RUNALL)) + func testSeparateLoops() { let input = [(1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testNineElements() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("nine elements", .enabled(if: RUNALL)) + func testNineElements() { let input = [(1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6)] - XCTAssertTrue(Dominoes(input).chained) + #expect(Dominoes(input).chained) } - func testSeparateThreeDominoLoops() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("separate three-domino loops", .enabled(if: RUNALL)) + func testSeparateThreeDominoLoops() { let input = [(1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4)] - XCTAssertFalse(Dominoes(input).chained) + #expect(!Dominoes(input).chained) } } diff --git a/exercises/practice/etl/.meta/template.swift b/exercises/practice/etl/.meta/template.swift index 1a3729cc5..480587337 100644 --- a/exercises/practice/etl/.meta/template.swift +++ b/exercises/practice/etl/.meta/template.swift @@ -1,20 +1,22 @@ -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 }}() { let legacy = {{case.input.legacy | toStringDictionary}} let expected = {{case.expected | toStringDictionary}} let results = ETL.transform(legacy) - XCTAssertEqual(results, expected) + #expect(results == expected) } {% endfor -%} } diff --git a/exercises/practice/etl/Package.swift b/exercises/practice/etl/Package.swift index b42b58083..8ca694bf2 100644 --- a/exercises/practice/etl/Package.swift +++ b/exercises/practice/etl/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/etl/Tests/EtlTests/EtlTests.swift b/exercises/practice/etl/Tests/EtlTests/EtlTests.swift index 8c08adae9..6c14b94df 100644 --- a/exercises/practice/etl/Tests/EtlTests/EtlTests.swift +++ b/exercises/practice/etl/Tests/EtlTests/EtlTests.swift @@ -1,38 +1,41 @@ -import XCTest +import Foundation +import Testing @testable import Etl -class EtlTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct EtlTests { + + @Test("single letter") func testSingleLetter() { let legacy = ["1": ["A"]] let expected = ["a": 1] let results = ETL.transform(legacy) - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testSingleScoreWithMultipleLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("single score with multiple letters", .enabled(if: RUNALL)) + func testSingleScoreWithMultipleLetters() { let legacy = ["1": ["A", "E", "I", "O", "U"]] let expected = ["a": 1, "e": 1, "i": 1, "o": 1, "u": 1] let results = ETL.transform(legacy) - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testMultipleScoresWithMultipleLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("multiple scores with multiple letters", .enabled(if: RUNALL)) + func testMultipleScoresWithMultipleLetters() { let legacy = ["1": ["A", "E"], "2": ["D", "G"]] let expected = ["a": 1, "d": 2, "e": 1, "g": 2] let results = ETL.transform(legacy) - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testMultipleScoresWithDifferingNumbersOfLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("multiple scores with differing numbers of letters", .enabled(if: RUNALL)) + func testMultipleScoresWithDifferingNumbersOfLetters() { let legacy = [ "1": ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], "10": ["Q", "Z"], "2": ["D", "G"], "3": ["B", "C", "M", "P"], "4": ["F", "H", "V", "W", "Y"], "5": ["K"], "8": ["J", "X"], @@ -44,6 +47,6 @@ class EtlTests: XCTestCase { ] let results = ETL.transform(legacy) - XCTAssertEqual(results, expected) + #expect(results == expected) } }