diff --git a/exercises/practice/scrabble-score/.meta/template.swift b/exercises/practice/scrabble-score/.meta/template.swift index a2148d659..5a8b3e55a 100644 --- a/exercises/practice/scrabble-score/.meta/template.swift +++ b/exercises/practice/scrabble-score/.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(score("{{case.input.word}}"), {{case.expected}}) + func test{{case.description |camelCase }}() { + #expect(score("{{case.input.word}}") == {{case.expected}}) } {% endfor -%} } diff --git a/exercises/practice/scrabble-score/Package.swift b/exercises/practice/scrabble-score/Package.swift index d9ec5cdf2..5caaa3c75 100644 --- a/exercises/practice/scrabble-score/Package.swift +++ b/exercises/practice/scrabble-score/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/scrabble-score/Tests/ScrabbleScoreTests/ScrabbleScoreTests.swift b/exercises/practice/scrabble-score/Tests/ScrabbleScoreTests/ScrabbleScoreTests.swift index 1fb46888f..0b88765b9 100644 --- a/exercises/practice/scrabble-score/Tests/ScrabbleScoreTests/ScrabbleScoreTests.swift +++ b/exercises/practice/scrabble-score/Tests/ScrabbleScoreTests/ScrabbleScoreTests.swift @@ -1,61 +1,64 @@ -import XCTest +import Foundation +import Testing @testable import ScrabbleScore -class ScrabbleScoreTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct ScrabbleScoreTests { + + @Test("lowercase letter") func testLowercaseLetter() { - XCTAssertEqual(score("a"), 1) + #expect(score("a") == 1) } - func testUppercaseLetter() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("A"), 1) + @Test("uppercase letter", .enabled(if: RUNALL)) + func testUppercaseLetter() { + #expect(score("A") == 1) } - func testValuableLetter() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("f"), 4) + @Test("valuable letter", .enabled(if: RUNALL)) + func testValuableLetter() { + #expect(score("f") == 4) } - func testShortWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("at"), 2) + @Test("short word", .enabled(if: RUNALL)) + func testShortWord() { + #expect(score("at") == 2) } - func testShortValuableWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("zoo"), 12) + @Test("short, valuable word", .enabled(if: RUNALL)) + func testShortValuableWord() { + #expect(score("zoo") == 12) } - func testMediumWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("street"), 6) + @Test("medium word", .enabled(if: RUNALL)) + func testMediumWord() { + #expect(score("street") == 6) } - func testMediumValuableWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("quirky"), 22) + @Test("medium, valuable word", .enabled(if: RUNALL)) + func testMediumValuableWord() { + #expect(score("quirky") == 22) } - func testLongMixedCaseWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("OxyphenButazone"), 41) + @Test("long, mixed-case word", .enabled(if: RUNALL)) + func testLongMixedCaseWord() { + #expect(score("OxyphenButazone") == 41) } - func testEnglishLikeWord() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("pinata"), 8) + @Test("english-like word", .enabled(if: RUNALL)) + func testEnglishLikeWord() { + #expect(score("pinata") == 8) } - func testEmptyInput() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score(""), 0) + @Test("empty input", .enabled(if: RUNALL)) + func testEmptyInput() { + #expect(score("") == 0) } - func testEntireAlphabetAvailable() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(score("abcdefghijklmnopqrstuvwxyz"), 87) + @Test("entire alphabet available", .enabled(if: RUNALL)) + func testEntireAlphabetAvailable() { + #expect(score("abcdefghijklmnopqrstuvwxyz") == 87) } } diff --git a/exercises/practice/secret-handshake/.meta/template.swift b/exercises/practice/secret-handshake/.meta/template.swift index 7f22a2f50..10df1d2f4 100644 --- a/exercises/practice/secret-handshake/.meta/template.swift +++ b/exercises/practice/secret-handshake/.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(commands(number: {{case.input.number}}), {{case.expected | toStringArray}}) + func test{{case.description |camelCase }}() { + #expect(commands(number: {{case.input.number}}) == {{case.expected | toStringArray}}) } {% endfor -%} } diff --git a/exercises/practice/secret-handshake/Package.swift b/exercises/practice/secret-handshake/Package.swift index a24fb98b5..6313b5513 100644 --- a/exercises/practice/secret-handshake/Package.swift +++ b/exercises/practice/secret-handshake/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/secret-handshake/Tests/SecretHandshakeTests/SecretHandshakeTests.swift b/exercises/practice/secret-handshake/Tests/SecretHandshakeTests/SecretHandshakeTests.swift index 986587037..9a7484012 100644 --- a/exercises/practice/secret-handshake/Tests/SecretHandshakeTests/SecretHandshakeTests.swift +++ b/exercises/practice/secret-handshake/Tests/SecretHandshakeTests/SecretHandshakeTests.swift @@ -1,61 +1,64 @@ -import XCTest +import Foundation +import Testing @testable import SecretHandshake -class SecretHandshakeTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct SecretHandshakeTests { + + @Test("wink for 1") func testWinkFor1() { - XCTAssertEqual(commands(number: 1), ["wink"]) + #expect(commands(number: 1) == ["wink"]) } - func testDoubleBlinkFor10() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 2), ["double blink"]) + @Test("double blink for 10", .enabled(if: RUNALL)) + func testDoubleBlinkFor10() { + #expect(commands(number: 2) == ["double blink"]) } - func testCloseYourEyesFor100() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 4), ["close your eyes"]) + @Test("close your eyes for 100", .enabled(if: RUNALL)) + func testCloseYourEyesFor100() { + #expect(commands(number: 4) == ["close your eyes"]) } - func testJumpFor1000() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 8), ["jump"]) + @Test("jump for 1000", .enabled(if: RUNALL)) + func testJumpFor1000() { + #expect(commands(number: 8) == ["jump"]) } - func testCombineTwoActions() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 3), ["wink", "double blink"]) + @Test("combine two actions", .enabled(if: RUNALL)) + func testCombineTwoActions() { + #expect(commands(number: 3) == ["wink", "double blink"]) } - func testReverseTwoActions() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 19), ["double blink", "wink"]) + @Test("reverse two actions", .enabled(if: RUNALL)) + func testReverseTwoActions() { + #expect(commands(number: 19) == ["double blink", "wink"]) } - func testReversingOneActionGivesTheSameAction() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 24), ["jump"]) + @Test("reversing one action gives the same action", .enabled(if: RUNALL)) + func testReversingOneActionGivesTheSameAction() { + #expect(commands(number: 24) == ["jump"]) } - func testReversingNoActionsStillGivesNoActions() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 16), []) + @Test("reversing no actions still gives no actions", .enabled(if: RUNALL)) + func testReversingNoActionsStillGivesNoActions() { + #expect(commands(number: 16) == []) } - func testAllPossibleActions() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 15), ["wink", "double blink", "close your eyes", "jump"]) + @Test("all possible actions", .enabled(if: RUNALL)) + func testAllPossibleActions() { + #expect(commands(number: 15) == ["wink", "double blink", "close your eyes", "jump"]) } - func testReverseAllPossibleActions() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 31), ["jump", "close your eyes", "double blink", "wink"]) + @Test("reverse all possible actions", .enabled(if: RUNALL)) + func testReverseAllPossibleActions() { + #expect(commands(number: 31) == ["jump", "close your eyes", "double blink", "wink"]) } - func testDoNothingForZero() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(commands(number: 0), []) + @Test("do nothing for zero", .enabled(if: RUNALL)) + func testDoNothingForZero() { + #expect(commands(number: 0) == []) } } diff --git a/exercises/practice/series/.meta/template.swift b/exercises/practice/series/.meta/template.swift index 0c2ccc496..5dce28499 100644 --- a/exercises/practice/series/.meta/template.swift +++ b/exercises/practice/series/.meta/template.swift @@ -1,28 +1,31 @@ -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 series = Series("{{case.input.series}}") {%- if case.expected.error %} - XCTAssertThrowsError(try series.slice({{case.input.sliceLength}})) { error in + #expect(throws: {% if case.expected.error == "slice length cannot be greater than series length" -%} - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthLongerThanSeries) + SeriesError.sliceLengthLongerThanSeries {%- elif case.expected.error == "series cannot be empty" -%} - XCTAssertEqual(error as? SeriesError, SeriesError.emptySeries) + SeriesError.emptySeries {%- elif case.expected.error == "slice length cannot be negative" or case.expected.error == "slice length cannot be zero" -%} - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthZeroOrLess) + SeriesError.sliceLengthZeroOrLess {%- endif %} - } + ) + {try series.slice({{case.input.sliceLength}})} {%- else %} - XCTAssertEqual(try! series.slice({{case.input.sliceLength}}), {{case.expected | toStringArray}}) + #expect(try! series.slice({{case.input.sliceLength}}) == {{case.expected | toStringArray}}) {%- endif %} } {% endfor -%} diff --git a/exercises/practice/series/Package.swift b/exercises/practice/series/Package.swift index 1be203b63..b1a9a1f49 100644 --- a/exercises/practice/series/Package.swift +++ b/exercises/practice/series/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/series/Tests/SeriesTests/SeriesTests.swift b/exercises/practice/series/Tests/SeriesTests/SeriesTests.swift index a67a16188..44a15eaa9 100644 --- a/exercises/practice/series/Tests/SeriesTests/SeriesTests.swift +++ b/exercises/practice/series/Tests/SeriesTests/SeriesTests.swift @@ -1,84 +1,93 @@ -import XCTest +import Foundation +import Testing @testable import Series -class SeriesTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct SeriesTests { + + @Test("slices of one from one") func testSlicesOfOneFromOne() { let series = Series("1") - XCTAssertEqual(try! series.slice(1), ["1"]) + #expect(try! series.slice(1) == ["1"]) } - func testSlicesOfOneFromTwo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slices of one from two", .enabled(if: RUNALL)) + func testSlicesOfOneFromTwo() { let series = Series("12") - XCTAssertEqual(try! series.slice(1), ["1", "2"]) + #expect(try! series.slice(1) == ["1", "2"]) } - func testSlicesOfTwo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slices of two", .enabled(if: RUNALL)) + func testSlicesOfTwo() { let series = Series("35") - XCTAssertEqual(try! series.slice(2), ["35"]) + #expect(try! series.slice(2) == ["35"]) } - func testSlicesOfTwoOverlap() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slices of two overlap", .enabled(if: RUNALL)) + func testSlicesOfTwoOverlap() { let series = Series("9142") - XCTAssertEqual(try! series.slice(2), ["91", "14", "42"]) + #expect(try! series.slice(2) == ["91", "14", "42"]) } - func testSlicesCanIncludeDuplicates() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slices can include duplicates", .enabled(if: RUNALL)) + func testSlicesCanIncludeDuplicates() { let series = Series("777777") - XCTAssertEqual(try! series.slice(3), ["777", "777", "777", "777"]) + #expect(try! series.slice(3) == ["777", "777", "777", "777"]) } - func testSlicesOfALongSeries() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slices of a long series", .enabled(if: RUNALL)) + func testSlicesOfALongSeries() { let series = Series("918493904243") - XCTAssertEqual( - try! series.slice(5), - ["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"]) + #expect( + try! series.slice(5) == [ + "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243", + ]) } - func testSliceLengthIsTooLarge() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slice length is too large", .enabled(if: RUNALL)) + func testSliceLengthIsTooLarge() { let series = Series("12345") - XCTAssertThrowsError(try series.slice(6)) { error in - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthLongerThanSeries) - } + #expect( + throws: + SeriesError.sliceLengthLongerThanSeries + ) { try series.slice(6) } } - func testSliceLengthIsWayTooLarge() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slice length is way too large", .enabled(if: RUNALL)) + func testSliceLengthIsWayTooLarge() { let series = Series("12345") - XCTAssertThrowsError(try series.slice(42)) { error in - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthLongerThanSeries) - } + #expect( + throws: + SeriesError.sliceLengthLongerThanSeries + ) { try series.slice(42) } } - func testSliceLengthCannotBeZero() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slice length cannot be zero", .enabled(if: RUNALL)) + func testSliceLengthCannotBeZero() { let series = Series("12345") - XCTAssertThrowsError(try series.slice(0)) { error in - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthZeroOrLess) - } + #expect( + throws: + SeriesError.sliceLengthZeroOrLess + ) { try series.slice(0) } } - func testSliceLengthCannotBeNegative() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("slice length cannot be negative", .enabled(if: RUNALL)) + func testSliceLengthCannotBeNegative() { let series = Series("123") - XCTAssertThrowsError(try series.slice(-1)) { error in - XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthZeroOrLess) - } + #expect( + throws: + SeriesError.sliceLengthZeroOrLess + ) { try series.slice(-1) } } - func testEmptySeriesIsInvalid() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("empty series is invalid", .enabled(if: RUNALL)) + func testEmptySeriesIsInvalid() { let series = Series("") - XCTAssertThrowsError(try series.slice(1)) { error in - XCTAssertEqual(error as? SeriesError, SeriesError.emptySeries) - } + #expect( + throws: + SeriesError.emptySeries + ) { try series.slice(1) } } } diff --git a/exercises/practice/sieve/.meta/template.swift b/exercises/practice/sieve/.meta/template.swift index d418af5fc..386bc2821 100644 --- a/exercises/practice/sieve/.meta/template.swift +++ b/exercises/practice/sieve/.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(sieve(limit: {{case.input.limit}}), {{case.expected}}) + func test{{case.description |camelCase }}() { + #expect(sieve(limit: {{case.input.limit}}) == {{case.expected}}) } {% endfor -%} } diff --git a/exercises/practice/sieve/Package.swift b/exercises/practice/sieve/Package.swift index 1c8f201bd..4b5fa7475 100644 --- a/exercises/practice/sieve/Package.swift +++ b/exercises/practice/sieve/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/sieve/Tests/SieveTests/SieveTests.swift b/exercises/practice/sieve/Tests/SieveTests/SieveTests.swift index d2dde4dba..1452bacc1 100644 --- a/exercises/practice/sieve/Tests/SieveTests/SieveTests.swift +++ b/exercises/practice/sieve/Tests/SieveTests/SieveTests.swift @@ -1,34 +1,36 @@ -import XCTest +import Foundation +import Testing @testable import Sieve -class SieveTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct SieveTests { + + @Test("no primes under two") func testNoPrimesUnderTwo() { - XCTAssertEqual(sieve(limit: 1), []) + #expect(sieve(limit: 1) == []) } - func testFindFirstPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(sieve(limit: 2), [2]) + @Test("find first prime", .enabled(if: RUNALL)) + func testFindFirstPrime() { + #expect(sieve(limit: 2) == [2]) } - func testFindPrimesUpTo10() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(sieve(limit: 10), [2, 3, 5, 7]) + @Test("find primes up to 10", .enabled(if: RUNALL)) + func testFindPrimesUpTo10() { + #expect(sieve(limit: 10) == [2, 3, 5, 7]) } - func testLimitIsPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(sieve(limit: 13), [2, 3, 5, 7, 11, 13]) + @Test("limit is prime", .enabled(if: RUNALL)) + func testLimitIsPrime() { + #expect(sieve(limit: 13) == [2, 3, 5, 7, 11, 13]) } - func testFindPrimesUpTo1000() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - sieve(limit: 1000), - [ + @Test("find primes up to 1000", .enabled(if: RUNALL)) + func testFindPrimesUpTo1000() { + #expect( + sieve(limit: 1000) == [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,