diff --git a/exercises/practice/tournament/.meta/template.swift b/exercises/practice/tournament/.meta/template.swift index 8c7377a67..c453d311e 100644 --- a/exercises/practice/tournament/.meta/template.swift +++ b/exercises/practice/tournament/.meta/template.swift @@ -1,26 +1,29 @@ -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 { private var tournament: Tournament! - override func setUp() { + init() { tournament = Tournament() } {% 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 }}() { {% for row in case.input.rows -%} tournament.addMatch("{{row}}") {% endfor -%} let expected = {{case.expected | toStringArray }} - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } {% endfor -%} } diff --git a/exercises/practice/tournament/Package.swift b/exercises/practice/tournament/Package.swift index ffc25f0ec..03f316b42 100644 --- a/exercises/practice/tournament/Package.swift +++ b/exercises/practice/tournament/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/tournament/Tests/TournamentTests/TournamentTests.swift b/exercises/practice/tournament/Tests/TournamentTests/TournamentTests.swift index 9cae0180e..d24bd9332 100644 --- a/exercises/practice/tournament/Tests/TournamentTests/TournamentTests.swift +++ b/exercises/practice/tournament/Tests/TournamentTests/TournamentTests.swift @@ -1,67 +1,69 @@ -import XCTest +import Foundation +import Testing @testable import Tournament -class TournamentTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct TournamentTests { private var tournament: Tournament! - override func setUp() { + init() { tournament = Tournament() } + @Test("just the header if no input") func testJustTheHeaderIfNoInput() { let expected = ["Team | MP | W | D | L | P"] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testAWinIsThreePointsALossIsZeroPoints() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a win is three points, a loss is zero points", .enabled(if: RUNALL)) + func testAWinIsThreePointsALossIsZeroPoints() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") let expected = [ "Team | MP | W | D | L | P", "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3", "Blithering Badgers | 1 | 0 | 0 | 1 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testAWinCanAlsoBeExpressedAsALoss() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a win can also be expressed as a loss", .enabled(if: RUNALL)) + func testAWinCanAlsoBeExpressedAsALoss() { tournament.addMatch("Blithering Badgers;Allegoric Alaskans;loss") let expected = [ "Team | MP | W | D | L | P", "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3", "Blithering Badgers | 1 | 0 | 0 | 1 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testADifferentTeamCanWin() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a different team can win", .enabled(if: RUNALL)) + func testADifferentTeamCanWin() { tournament.addMatch("Blithering Badgers;Allegoric Alaskans;win") let expected = [ "Team | MP | W | D | L | P", "Blithering Badgers | 1 | 1 | 0 | 0 | 3", "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testADrawIsOnePointEach() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a draw is one point each", .enabled(if: RUNALL)) + func testADrawIsOnePointEach() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;draw") let expected = [ "Team | MP | W | D | L | P", "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1", "Blithering Badgers | 1 | 0 | 1 | 0 | 1", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testThereCanBeMoreThanOneMatch() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("There can be more than one match", .enabled(if: RUNALL)) + func testThereCanBeMoreThanOneMatch() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") let expected = [ @@ -69,11 +71,11 @@ class TournamentTests: XCTestCase { "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6", "Blithering Badgers | 2 | 0 | 0 | 2 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testThereCanBeMoreThanOneWinner() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("There can be more than one winner", .enabled(if: RUNALL)) + func testThereCanBeMoreThanOneWinner() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;loss") tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") let expected = [ @@ -81,11 +83,11 @@ class TournamentTests: XCTestCase { "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3", "Blithering Badgers | 2 | 1 | 0 | 1 | 3", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testThereCanBeMoreThanTwoTeams() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("There can be more than two teams", .enabled(if: RUNALL)) + func testThereCanBeMoreThanTwoTeams() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") tournament.addMatch("Blithering Badgers;Courageous Californians;win") tournament.addMatch("Courageous Californians;Allegoric Alaskans;loss") @@ -95,11 +97,11 @@ class TournamentTests: XCTestCase { "Blithering Badgers | 2 | 1 | 0 | 1 | 3", "Courageous Californians | 2 | 0 | 0 | 2 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testTypicalInput() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("typical input", .enabled(if: RUNALL)) + func testTypicalInput() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") tournament.addMatch("Devastating Donkeys;Courageous Californians;draw") tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;win") @@ -113,11 +115,11 @@ class TournamentTests: XCTestCase { "Blithering Badgers | 3 | 1 | 0 | 2 | 3", "Courageous Californians | 3 | 0 | 1 | 2 | 1", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testIncompleteCompetitionNotAllPairsHavePlayed() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("incomplete competition (not all pairs have played)", .enabled(if: RUNALL)) + func testIncompleteCompetitionNotAllPairsHavePlayed() { tournament.addMatch("Allegoric Alaskans;Blithering Badgers;loss") tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;loss") tournament.addMatch("Courageous Californians;Blithering Badgers;draw") @@ -129,11 +131,11 @@ class TournamentTests: XCTestCase { "Courageous Californians | 2 | 0 | 1 | 1 | 1", "Devastating Donkeys | 1 | 0 | 0 | 1 | 0", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testTiesBrokenAlphabetically() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("ties broken alphabetically", .enabled(if: RUNALL)) + func testTiesBrokenAlphabetically() { tournament.addMatch("Courageous Californians;Devastating Donkeys;win") tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win") tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;loss") @@ -147,11 +149,11 @@ class TournamentTests: XCTestCase { "Blithering Badgers | 3 | 0 | 1 | 2 | 1", "Devastating Donkeys | 3 | 0 | 1 | 2 | 1", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } - func testEnsurePointsSortedNumerically() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("ensure points sorted numerically", .enabled(if: RUNALL)) + func testEnsurePointsSortedNumerically() { tournament.addMatch("Devastating Donkeys;Blithering Badgers;win") tournament.addMatch("Devastating Donkeys;Blithering Badgers;win") tournament.addMatch("Devastating Donkeys;Blithering Badgers;win") @@ -162,6 +164,6 @@ class TournamentTests: XCTestCase { "Devastating Donkeys | 5 | 4 | 0 | 1 | 12", "Blithering Badgers | 5 | 1 | 0 | 4 | 3", ] - XCTAssertEqual(tournament.tally(), expected) + #expect(tournament.tally() == expected) } } diff --git a/exercises/practice/transpose/.meta/template.swift b/exercises/practice/transpose/.meta/template.swift index 4d1c33a49..235e32b6d 100644 --- a/exercises/practice/transpose/.meta/template.swift +++ b/exercises/practice/transpose/.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(Transpose.transpose({{case.input.lines | toStringArray }}), {{case.expected | toStringArray}}) + func test{{case.description |camelCase }}() { + #expect(Transpose.transpose({{case.input.lines | toStringArray }}) == {{case.expected | toStringArray}}) } {% endfor -%} } diff --git a/exercises/practice/transpose/Package.swift b/exercises/practice/transpose/Package.swift index ed4298ddd..d430019d9 100644 --- a/exercises/practice/transpose/Package.swift +++ b/exercises/practice/transpose/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/transpose/Tests/TransposeTests/TransposeTests.swift b/exercises/practice/transpose/Tests/TransposeTests/TransposeTests.swift index e64b33afa..3850b893b 100644 --- a/exercises/practice/transpose/Tests/TransposeTests/TransposeTests.swift +++ b/exercises/practice/transpose/Tests/TransposeTests/TransposeTests.swift @@ -1,91 +1,96 @@ -import XCTest +import Foundation +import Testing @testable import Transpose -class TransposeTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct TransposeTests { + + @Test("empty string") func testEmptyString() { - XCTAssertEqual(Transpose.transpose([]), []) + #expect(Transpose.transpose([]) == []) } - func testTwoCharactersInARow() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(Transpose.transpose(["A1"]), ["A", "1"]) + @Test("two characters in a row", .enabled(if: RUNALL)) + func testTwoCharactersInARow() { + #expect(Transpose.transpose(["A1"]) == ["A", "1"]) } - func testTwoCharactersInAColumn() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(Transpose.transpose(["A", "1"]), ["A1"]) + @Test("two characters in a column", .enabled(if: RUNALL)) + func testTwoCharactersInAColumn() { + #expect(Transpose.transpose(["A", "1"]) == ["A1"]) } - func testSimple() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(Transpose.transpose(["ABC", "123"]), ["A1", "B2", "C3"]) + @Test("simple", .enabled(if: RUNALL)) + func testSimple() { + #expect(Transpose.transpose(["ABC", "123"]) == ["A1", "B2", "C3"]) } - func testSingleLine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["Single line."]), - ["S", "i", "n", "g", "l", "e", " ", "l", "i", "n", "e", "."]) + @Test("single line", .enabled(if: RUNALL)) + func testSingleLine() { + #expect( + Transpose.transpose(["Single line."]) == [ + "S", "i", "n", "g", "l", "e", " ", "l", "i", "n", "e", ".", + ]) } - func testFirstLineLongerThanSecondLine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["The fourth line.", "The fifth line."]), - [ + @Test("first line longer than second line", .enabled(if: RUNALL)) + func testFirstLineLongerThanSecondLine() { + #expect( + Transpose.transpose(["The fourth line.", "The fifth line."]) == [ "TT", "hh", "ee", " ", "ff", "oi", "uf", "rt", "th", "h ", " l", "li", "in", "ne", "e.", ".", ]) } - func testSecondLineLongerThanFirstLine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["The first line.", "The second line."]), - [ + @Test("second line longer than first line", .enabled(if: RUNALL)) + func testSecondLineLongerThanFirstLine() { + #expect( + Transpose.transpose(["The first line.", "The second line."]) == [ "TT", "hh", "ee", " ", "fs", "ie", "rc", "so", "tn", " d", "l ", "il", "ni", "en", ".e", " .", ]) } - func testMixedLineLength() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["The longest line.", "A long line.", "A longer line.", "A line."]), - [ + @Test("mixed line length", .enabled(if: RUNALL)) + func testMixedLineLength() { + #expect( + Transpose.transpose(["The longest line.", "A long line.", "A longer line.", "A line."]) == [ "TAAA", "h ", "elll", " ooi", "lnnn", "ogge", "n e.", "glr", "ei ", "snl", "tei", " .n", "l e", "i .", "n", "e", ".", ]) } - func testSquare() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["HEART", "EMBER", "ABUSE", "RESIN", "TREND"]), - ["HEART", "EMBER", "ABUSE", "RESIN", "TREND"]) + @Test("square", .enabled(if: RUNALL)) + func testSquare() { + #expect( + Transpose.transpose(["HEART", "EMBER", "ABUSE", "RESIN", "TREND"]) == [ + "HEART", "EMBER", "ABUSE", "RESIN", "TREND", + ]) } - func testRectangle() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["FRACTURE", "OUTLINED", "BLOOMING", "SEPTETTE"]), - ["FOBS", "RULE", "ATOP", "CLOT", "TIME", "UNIT", "RENT", "EDGE"]) + @Test("rectangle", .enabled(if: RUNALL)) + func testRectangle() { + #expect( + Transpose.transpose(["FRACTURE", "OUTLINED", "BLOOMING", "SEPTETTE"]) == [ + "FOBS", "RULE", "ATOP", "CLOT", "TIME", "UNIT", "RENT", "EDGE", + ]) } - func testTriangle() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["T", "EE", "AAA", "SSSS", "EEEEE", "RRRRRR"]), - ["TEASER", " EASER", " ASER", " SER", " ER", " R"]) + @Test("triangle", .enabled(if: RUNALL)) + func testTriangle() { + #expect( + Transpose.transpose(["T", "EE", "AAA", "SSSS", "EEEEE", "RRRRRR"]) == [ + "TEASER", " EASER", " ASER", " SER", " ER", " R", + ]) } - func testJaggedTriangle() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - Transpose.transpose(["11", "2", "3333", "444", "555555", "66666"]), - ["123456", "1 3456", " 3456", " 3 56", " 56", " 5"]) + @Test("jagged triangle", .enabled(if: RUNALL)) + func testJaggedTriangle() { + #expect( + Transpose.transpose(["11", "2", "3333", "444", "555555", "66666"]) == [ + "123456", "1 3456", " 3456", " 3 56", " 56", " 5", + ]) } } diff --git a/exercises/practice/triangle/.meta/template.swift b/exercises/practice/triangle/.meta/template.swift index efac1b2db..06a7206f9 100644 --- a/exercises/practice/triangle/.meta/template.swift +++ b/exercises/practice/triangle/.meta/template.swift @@ -1,20 +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 }}{{ forloop.outer.counter }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() 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 }}{{ forloop.outer.counter }}() { {%- if subCases.expected %} - XCTAssertTrue(Triangle({{subCases.input.sides}}).is{{subCases.property | capitalize }}) + #expect(Triangle({{subCases.input.sides}}).is{{subCases.property | capitalize }}) {%- else %} - XCTAssertFalse(Triangle({{subCases.input.sides}}).is{{subCases.property | capitalize }}) + #expect(!Triangle({{subCases.input.sides}}).is{{subCases.property | capitalize }}) {%- endif %} } {% endfor -%} diff --git a/exercises/practice/triangle/Package.swift b/exercises/practice/triangle/Package.swift index 4c751eee5..f4a121eb3 100644 --- a/exercises/practice/triangle/Package.swift +++ b/exercises/practice/triangle/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/triangle/Tests/TriangleTests/TriangleTests.swift b/exercises/practice/triangle/Tests/TriangleTests/TriangleTests.swift index a1a0ee3cb..3b14f2849 100644 --- a/exercises/practice/triangle/Tests/TriangleTests/TriangleTests.swift +++ b/exercises/practice/triangle/Tests/TriangleTests/TriangleTests.swift @@ -1,111 +1,114 @@ -import XCTest +import Foundation +import Testing @testable import Triangle -class TriangleTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct TriangleTests { + + @Test("all sides are equal") func testAllSidesAreEqual1() { - XCTAssertTrue(Triangle([2, 2, 2]).isEquilateral) + #expect(Triangle([2, 2, 2]).isEquilateral) } - func testAnySideIsUnequal1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([2, 3, 2]).isEquilateral) + @Test("any side is unequal", .enabled(if: RUNALL)) + func testAnySideIsUnequal1() { + #expect(!Triangle([2, 3, 2]).isEquilateral) } - func testNoSidesAreEqual1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([5, 4, 6]).isEquilateral) + @Test("no sides are equal", .enabled(if: RUNALL)) + func testNoSidesAreEqual1() { + #expect(!Triangle([5, 4, 6]).isEquilateral) } - func testAllZeroSidesIsNotATriangle1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([0, 0, 0]).isEquilateral) + @Test("all zero sides is not a triangle", .enabled(if: RUNALL)) + func testAllZeroSidesIsNotATriangle1() { + #expect(!Triangle([0, 0, 0]).isEquilateral) } - func testSidesMayBeFloats1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([0.5, 0.5, 0.5]).isEquilateral) + @Test("sides may be floats", .enabled(if: RUNALL)) + func testSidesMayBeFloats1() { + #expect(Triangle([0.5, 0.5, 0.5]).isEquilateral) } - func testLastTwoSidesAreEqual2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([3, 4, 4]).isIsosceles) + @Test("last two sides are equal", .enabled(if: RUNALL)) + func testLastTwoSidesAreEqual2() { + #expect(Triangle([3, 4, 4]).isIsosceles) } - func testFirstTwoSidesAreEqual2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([4, 4, 3]).isIsosceles) + @Test("first two sides are equal", .enabled(if: RUNALL)) + func testFirstTwoSidesAreEqual2() { + #expect(Triangle([4, 4, 3]).isIsosceles) } - func testFirstAndLastSidesAreEqual2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([4, 3, 4]).isIsosceles) + @Test("first and last sides are equal", .enabled(if: RUNALL)) + func testFirstAndLastSidesAreEqual2() { + #expect(Triangle([4, 3, 4]).isIsosceles) } - func testEquilateralTrianglesAreAlsoIsosceles2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([4, 4, 4]).isIsosceles) + @Test("equilateral triangles are also isosceles", .enabled(if: RUNALL)) + func testEquilateralTrianglesAreAlsoIsosceles2() { + #expect(Triangle([4, 4, 4]).isIsosceles) } - func testNoSidesAreEqual2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([2, 3, 4]).isIsosceles) + @Test("no sides are equal", .enabled(if: RUNALL)) + func testNoSidesAreEqual2() { + #expect(!Triangle([2, 3, 4]).isIsosceles) } - func testFirstTriangleInequalityViolation2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([1, 1, 3]).isIsosceles) + @Test("first triangle inequality violation", .enabled(if: RUNALL)) + func testFirstTriangleInequalityViolation2() { + #expect(!Triangle([1, 1, 3]).isIsosceles) } - func testSecondTriangleInequalityViolation2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([1, 3, 1]).isIsosceles) + @Test("second triangle inequality violation", .enabled(if: RUNALL)) + func testSecondTriangleInequalityViolation2() { + #expect(!Triangle([1, 3, 1]).isIsosceles) } - func testThirdTriangleInequalityViolation2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([3, 1, 1]).isIsosceles) + @Test("third triangle inequality violation", .enabled(if: RUNALL)) + func testThirdTriangleInequalityViolation2() { + #expect(!Triangle([3, 1, 1]).isIsosceles) } - func testSidesMayBeFloats2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([0.5, 0.4, 0.5]).isIsosceles) + @Test("sides may be floats", .enabled(if: RUNALL)) + func testSidesMayBeFloats2() { + #expect(Triangle([0.5, 0.4, 0.5]).isIsosceles) } - func testNoSidesAreEqual3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([5, 4, 6]).isScalene) + @Test("no sides are equal", .enabled(if: RUNALL)) + func testNoSidesAreEqual3() { + #expect(Triangle([5, 4, 6]).isScalene) } - func testAllSidesAreEqual3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([4, 4, 4]).isScalene) + @Test("all sides are equal", .enabled(if: RUNALL)) + func testAllSidesAreEqual3() { + #expect(!Triangle([4, 4, 4]).isScalene) } - func testFirstAndSecondSidesAreEqual3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([4, 4, 3]).isScalene) + @Test("first and second sides are equal", .enabled(if: RUNALL)) + func testFirstAndSecondSidesAreEqual3() { + #expect(!Triangle([4, 4, 3]).isScalene) } - func testFirstAndThirdSidesAreEqual3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([3, 4, 3]).isScalene) + @Test("first and third sides are equal", .enabled(if: RUNALL)) + func testFirstAndThirdSidesAreEqual3() { + #expect(!Triangle([3, 4, 3]).isScalene) } - func testSecondAndThirdSidesAreEqual3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([4, 3, 3]).isScalene) + @Test("second and third sides are equal", .enabled(if: RUNALL)) + func testSecondAndThirdSidesAreEqual3() { + #expect(!Triangle([4, 3, 3]).isScalene) } - func testMayNotViolateTriangleInequality3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(Triangle([7, 3, 2]).isScalene) + @Test("may not violate triangle inequality", .enabled(if: RUNALL)) + func testMayNotViolateTriangleInequality3() { + #expect(!Triangle([7, 3, 2]).isScalene) } - func testSidesMayBeFloats3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(Triangle([0.5, 0.4, 0.6]).isScalene) + @Test("sides may be floats", .enabled(if: RUNALL)) + func testSidesMayBeFloats3() { + #expect(Triangle([0.5, 0.4, 0.6]).isScalene) } } diff --git a/exercises/practice/twelve-days/.meta/template.swift b/exercises/practice/twelve-days/.meta/template.swift index bdaf81588..6ae1acc6b 100644 --- a/exercises/practice/twelve-days/.meta/template.swift +++ b/exercises/practice/twelve-days/.meta/template.swift @@ -1,18 +1,20 @@ -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 }}{{ forloop.outer.counter }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() 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 }}{{ forloop.outer.counter }}() { let expected = "{{subCases.expected | join:"\n" + ""}}" - XCTAssertEqual(TwelveDaysSong.recite(start: {{subCases.input.startVerse}}, end: {{subCases.input.endVerse}}), expected) + #expect(TwelveDaysSong.recite(start: {{subCases.input.startVerse}}, end: {{subCases.input.endVerse}}) == expected) } {% endfor -%} {% endfor -%} diff --git a/exercises/practice/twelve-days/Package.swift b/exercises/practice/twelve-days/Package.swift index bde737e97..f166b62f3 100644 --- a/exercises/practice/twelve-days/Package.swift +++ b/exercises/practice/twelve-days/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/twelve-days/Tests/TwelveDaysTests/TwelveDaysTests.swift b/exercises/practice/twelve-days/Tests/TwelveDaysTests/TwelveDaysTests.swift index 5cfb3bc8d..3e5f2b891 100644 --- a/exercises/practice/twelve-days/Tests/TwelveDaysTests/TwelveDaysTests.swift +++ b/exercises/practice/twelve-days/Tests/TwelveDaysTests/TwelveDaysTests.swift @@ -1,113 +1,116 @@ -import XCTest +import Foundation +import Testing @testable import TwelveDays -class TwelveDaysTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct TwelveDaysTests { + + @Test("first day a partridge in a pear tree") func testFirstDayAPartridgeInAPearTree1() { let expected = "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 1, end: 1), expected) + #expect(TwelveDaysSong.recite(start: 1, end: 1) == expected) } - func testSecondDayTwoTurtleDoves1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("second day two turtle doves", .enabled(if: RUNALL)) + func testSecondDayTwoTurtleDoves1() { let expected = "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 2, end: 2), expected) + #expect(TwelveDaysSong.recite(start: 2, end: 2) == expected) } - func testThirdDayThreeFrenchHens1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("third day three french hens", .enabled(if: RUNALL)) + func testThirdDayThreeFrenchHens1() { let expected = "On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 3, end: 3), expected) + #expect(TwelveDaysSong.recite(start: 3, end: 3) == expected) } - func testFourthDayFourCallingBirds1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("fourth day four calling birds", .enabled(if: RUNALL)) + func testFourthDayFourCallingBirds1() { let expected = "On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 4, end: 4), expected) + #expect(TwelveDaysSong.recite(start: 4, end: 4) == expected) } - func testFifthDayFiveGoldRings1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("fifth day five gold rings", .enabled(if: RUNALL)) + func testFifthDayFiveGoldRings1() { let expected = "On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 5, end: 5), expected) + #expect(TwelveDaysSong.recite(start: 5, end: 5) == expected) } - func testSixthDaySixGeeseALaying1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("sixth day six geese-a-laying", .enabled(if: RUNALL)) + func testSixthDaySixGeeseALaying1() { let expected = "On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 6, end: 6), expected) + #expect(TwelveDaysSong.recite(start: 6, end: 6) == expected) } - func testSeventhDaySevenSwansASwimming1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("seventh day seven swans-a-swimming", .enabled(if: RUNALL)) + func testSeventhDaySevenSwansASwimming1() { let expected = "On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 7, end: 7), expected) + #expect(TwelveDaysSong.recite(start: 7, end: 7) == expected) } - func testEighthDayEightMaidsAMilking1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("eighth day eight maids-a-milking", .enabled(if: RUNALL)) + func testEighthDayEightMaidsAMilking1() { let expected = "On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 8, end: 8), expected) + #expect(TwelveDaysSong.recite(start: 8, end: 8) == expected) } - func testNinthDayNineLadiesDancing1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("ninth day nine ladies dancing", .enabled(if: RUNALL)) + func testNinthDayNineLadiesDancing1() { let expected = "On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 9, end: 9), expected) + #expect(TwelveDaysSong.recite(start: 9, end: 9) == expected) } - func testTenthDayTenLordsALeaping1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("tenth day ten lords-a-leaping", .enabled(if: RUNALL)) + func testTenthDayTenLordsALeaping1() { let expected = "On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 10, end: 10), expected) + #expect(TwelveDaysSong.recite(start: 10, end: 10) == expected) } - func testEleventhDayElevenPipersPiping1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("eleventh day eleven pipers piping", .enabled(if: RUNALL)) + func testEleventhDayElevenPipersPiping1() { let expected = "On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 11, end: 11), expected) + #expect(TwelveDaysSong.recite(start: 11, end: 11) == expected) } - func testTwelfthDayTwelveDrummersDrumming1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("twelfth day twelve drummers drumming", .enabled(if: RUNALL)) + func testTwelfthDayTwelveDrummersDrumming1() { let expected = "On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 12, end: 12), expected) + #expect(TwelveDaysSong.recite(start: 12, end: 12) == expected) } - func testRecitesFirstThreeVersesOfTheSong2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("recites first three verses of the song", .enabled(if: RUNALL)) + func testRecitesFirstThreeVersesOfTheSong2() { let expected = "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\n" + "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\n" + "On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 1, end: 3), expected) + #expect(TwelveDaysSong.recite(start: 1, end: 3) == expected) } - func testRecitesThreeVersesFromTheMiddleOfTheSong2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("recites three verses from the middle of the song", .enabled(if: RUNALL)) + func testRecitesThreeVersesFromTheMiddleOfTheSong2() { let expected = "On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" + "On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" + "On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 4, end: 6), expected) + #expect(TwelveDaysSong.recite(start: 4, end: 6) == expected) } - func testRecitesTheWholeSong2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("recites the whole song", .enabled(if: RUNALL)) + func testRecitesTheWholeSong2() { let expected = "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\n" + "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\n" @@ -121,6 +124,6 @@ class TwelveDaysTests: XCTestCase { + "On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" + "On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" + "On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree." - XCTAssertEqual(TwelveDaysSong.recite(start: 1, end: 12), expected) + #expect(TwelveDaysSong.recite(start: 1, end: 12) == expected) } }