From 906af5cb751912cb12f00895d9010dd69b7bccf6 Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 21 Dec 2024 20:10:34 +0100 Subject: [PATCH] Update Swift tools version to 6.0 and refactor test cases to use new testing framework --- .../roman-numerals/.meta/template.swift | 16 +- .../practice/roman-numerals/.meta/tests.toml | 3 + .../practice/roman-numerals/Package.swift | 2 +- .../RomanNumeralsTests.swift | 166 +++++++++--------- .../rotational-cipher/.meta/template.swift | 16 +- .../practice/rotational-cipher/Package.swift | 2 +- .../RotationalCipherTests.swift | 69 ++++---- .../run-length-encoding/.meta/template.swift | 20 ++- .../run-length-encoding/Package.swift | 2 +- .../RunLengthEncodingTests.swift | 91 +++++----- exercises/practice/say/.meta/template.swift | 20 ++- exercises/practice/say/Package.swift | 2 +- .../say/Tests/SayTests/SayTests.swift | 129 +++++++------- 13 files changed, 282 insertions(+), 256 deletions(-) diff --git a/exercises/practice/roman-numerals/.meta/template.swift b/exercises/practice/roman-numerals/.meta/template.swift index 80f239262..2f279137f 100644 --- a/exercises/practice/roman-numerals/.meta/template.swift +++ b/exercises/practice/roman-numerals/.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({{case.input.number}}.toRomanNumeral(), "{{case.expected}}") + func test{{case.description |camelCase }}() { + #expect({{case.input.number}}.toRomanNumeral() == "{{case.expected}}") } {% endfor -%} } diff --git a/exercises/practice/roman-numerals/.meta/tests.toml b/exercises/practice/roman-numerals/.meta/tests.toml index 57c6c4be8..709011b55 100644 --- a/exercises/practice/roman-numerals/.meta/tests.toml +++ b/exercises/practice/roman-numerals/.meta/tests.toml @@ -84,5 +84,8 @@ description = "3000 is MMM" [3bc4b41c-c2e6-49d9-9142-420691504336] description = "3001 is MMMI" +[2f89cad7-73f6-4d1b-857b-0ef531f68b7e] +description = "3888 is MMMDCCCLXXXVIII" + [4e18e96b-5fbb-43df-a91b-9cb511fe0856] description = "3999 is MMMCMXCIX" diff --git a/exercises/practice/roman-numerals/Package.swift b/exercises/practice/roman-numerals/Package.swift index 9fe58cb63..4f9d7ffe9 100644 --- a/exercises/practice/roman-numerals/Package.swift +++ b/exercises/practice/roman-numerals/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/roman-numerals/Tests/RomanNumeralsTests/RomanNumeralsTests.swift b/exercises/practice/roman-numerals/Tests/RomanNumeralsTests/RomanNumeralsTests.swift index 2a29cae0b..b8b0a3697 100644 --- a/exercises/practice/roman-numerals/Tests/RomanNumeralsTests/RomanNumeralsTests.swift +++ b/exercises/practice/roman-numerals/Tests/RomanNumeralsTests/RomanNumeralsTests.swift @@ -1,136 +1,144 @@ -import XCTest +import Foundation +import Testing @testable import RomanNumerals -class RomanNumeralsTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct RomanNumeralsTests { + + @Test("1 is I") func test1IsI() { - XCTAssertEqual(1.toRomanNumeral(), "I") + #expect(1.toRomanNumeral() == "I") + } + + @Test("2 is II", .enabled(if: RUNALL)) + func test2IsIi() { + #expect(2.toRomanNumeral() == "II") } - func test2IsIi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(2.toRomanNumeral(), "II") + @Test("3 is III", .enabled(if: RUNALL)) + func test3IsIii() { + #expect(3.toRomanNumeral() == "III") } - func test3IsIii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(3.toRomanNumeral(), "III") + @Test("4 is IV", .enabled(if: RUNALL)) + func test4IsIv() { + #expect(4.toRomanNumeral() == "IV") } - func test4IsIv() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(4.toRomanNumeral(), "IV") + @Test("5 is V", .enabled(if: RUNALL)) + func test5IsV() { + #expect(5.toRomanNumeral() == "V") } - func test5IsV() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(5.toRomanNumeral(), "V") + @Test("6 is VI", .enabled(if: RUNALL)) + func test6IsVi() { + #expect(6.toRomanNumeral() == "VI") } - func test6IsVi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(6.toRomanNumeral(), "VI") + @Test("9 is IX", .enabled(if: RUNALL)) + func test9IsIx() { + #expect(9.toRomanNumeral() == "IX") } - func test9IsIx() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(9.toRomanNumeral(), "IX") + @Test("16 is XVI", .enabled(if: RUNALL)) + func test16IsXvi() { + #expect(16.toRomanNumeral() == "XVI") } - func test16IsXvi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(16.toRomanNumeral(), "XVI") + @Test("27 is XXVII", .enabled(if: RUNALL)) + func test27IsXxvii() { + #expect(27.toRomanNumeral() == "XXVII") } - func test27IsXxvii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(27.toRomanNumeral(), "XXVII") + @Test("48 is XLVIII", .enabled(if: RUNALL)) + func test48IsXlviii() { + #expect(48.toRomanNumeral() == "XLVIII") } - func test48IsXlviii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(48.toRomanNumeral(), "XLVIII") + @Test("49 is XLIX", .enabled(if: RUNALL)) + func test49IsXlix() { + #expect(49.toRomanNumeral() == "XLIX") } - func test49IsXlix() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(49.toRomanNumeral(), "XLIX") + @Test("59 is LIX", .enabled(if: RUNALL)) + func test59IsLix() { + #expect(59.toRomanNumeral() == "LIX") } - func test59IsLix() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(59.toRomanNumeral(), "LIX") + @Test("66 is LXVI", .enabled(if: RUNALL)) + func test66IsLxvi() { + #expect(66.toRomanNumeral() == "LXVI") } - func test66IsLxvi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(66.toRomanNumeral(), "LXVI") + @Test("93 is XCIII", .enabled(if: RUNALL)) + func test93IsXciii() { + #expect(93.toRomanNumeral() == "XCIII") } - func test93IsXciii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(93.toRomanNumeral(), "XCIII") + @Test("141 is CXLI", .enabled(if: RUNALL)) + func test141IsCxli() { + #expect(141.toRomanNumeral() == "CXLI") } - func test141IsCxli() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(141.toRomanNumeral(), "CXLI") + @Test("163 is CLXIII", .enabled(if: RUNALL)) + func test163IsClxiii() { + #expect(163.toRomanNumeral() == "CLXIII") } - func test163IsClxiii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(163.toRomanNumeral(), "CLXIII") + @Test("166 is CLXVI", .enabled(if: RUNALL)) + func test166IsClxvi() { + #expect(166.toRomanNumeral() == "CLXVI") } - func test166IsClxvi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(166.toRomanNumeral(), "CLXVI") + @Test("402 is CDII", .enabled(if: RUNALL)) + func test402IsCdii() { + #expect(402.toRomanNumeral() == "CDII") } - func test402IsCdii() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(402.toRomanNumeral(), "CDII") + @Test("575 is DLXXV", .enabled(if: RUNALL)) + func test575IsDlxxv() { + #expect(575.toRomanNumeral() == "DLXXV") } - func test575IsDlxxv() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(575.toRomanNumeral(), "DLXXV") + @Test("666 is DCLXVI", .enabled(if: RUNALL)) + func test666IsDclxvi() { + #expect(666.toRomanNumeral() == "DCLXVI") } - func test666IsDclxvi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(666.toRomanNumeral(), "DCLXVI") + @Test("911 is CMXI", .enabled(if: RUNALL)) + func test911IsCmxi() { + #expect(911.toRomanNumeral() == "CMXI") } - func test911IsCmxi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(911.toRomanNumeral(), "CMXI") + @Test("1024 is MXXIV", .enabled(if: RUNALL)) + func test1024IsMxxiv() { + #expect(1024.toRomanNumeral() == "MXXIV") } - func test1024IsMxxiv() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(1024.toRomanNumeral(), "MXXIV") + @Test("1666 is MDCLXVI", .enabled(if: RUNALL)) + func test1666IsMdclxvi() { + #expect(1666.toRomanNumeral() == "MDCLXVI") } - func test1666IsMdclxvi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(1666.toRomanNumeral(), "MDCLXVI") + @Test("3000 is MMM", .enabled(if: RUNALL)) + func test3000IsMmm() { + #expect(3000.toRomanNumeral() == "MMM") } - func test3000IsMmm() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(3000.toRomanNumeral(), "MMM") + @Test("3001 is MMMI", .enabled(if: RUNALL)) + func test3001IsMmmi() { + #expect(3001.toRomanNumeral() == "MMMI") } - func test3001IsMmmi() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(3001.toRomanNumeral(), "MMMI") + @Test("3888 is MMMDCCCLXXXVIII", .enabled(if: RUNALL)) + func test3888IsMmmdccclxxxviii() { + #expect(3888.toRomanNumeral() == "MMMDCCCLXXXVIII") } - func test3999IsMmmcmxcix() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(3999.toRomanNumeral(), "MMMCMXCIX") + @Test("3999 is MMMCMXCIX", .enabled(if: RUNALL)) + func test3999IsMmmcmxcix() { + #expect(3999.toRomanNumeral() == "MMMCMXCIX") } } diff --git a/exercises/practice/rotational-cipher/.meta/template.swift b/exercises/practice/rotational-cipher/.meta/template.swift index 759c94f4a..e5884996a 100644 --- a/exercises/practice/rotational-cipher/.meta/template.swift +++ b/exercises/practice/rotational-cipher/.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(rotateCipher("{{case.input.text}}", shift: {{case.input.shiftKey}}), "{{case.expected}}") + func test{{case.description |camelCase }}() { + #expect(rotateCipher("{{case.input.text}}", shift: {{case.input.shiftKey}}) == "{{case.expected}}") } {% endfor -%} } diff --git a/exercises/practice/rotational-cipher/Package.swift b/exercises/practice/rotational-cipher/Package.swift index f945aba59..0d8be0c22 100644 --- a/exercises/practice/rotational-cipher/Package.swift +++ b/exercises/practice/rotational-cipher/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/rotational-cipher/Tests/RotationalCipherTests/RotationalCipherTests.swift b/exercises/practice/rotational-cipher/Tests/RotationalCipherTests/RotationalCipherTests.swift index b928030b7..4a93d529f 100644 --- a/exercises/practice/rotational-cipher/Tests/RotationalCipherTests/RotationalCipherTests.swift +++ b/exercises/practice/rotational-cipher/Tests/RotationalCipherTests/RotationalCipherTests.swift @@ -1,58 +1,61 @@ -import XCTest +import Foundation +import Testing @testable import RotationalCipher -class RotationalCipherTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct RotationalCipherTests { + + @Test("rotate a by 0, same output as input") func testRotateABy0SameOutputAsInput() { - XCTAssertEqual(rotateCipher("a", shift: 0), "a") + #expect(rotateCipher("a", shift: 0) == "a") } - func testRotateABy1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("a", shift: 1), "b") + @Test("rotate a by 1", .enabled(if: RUNALL)) + func testRotateABy1() { + #expect(rotateCipher("a", shift: 1) == "b") } - func testRotateABy26SameOutputAsInput() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("a", shift: 26), "a") + @Test("rotate a by 26, same output as input", .enabled(if: RUNALL)) + func testRotateABy26SameOutputAsInput() { + #expect(rotateCipher("a", shift: 26) == "a") } - func testRotateMBy13() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("m", shift: 13), "z") + @Test("rotate m by 13", .enabled(if: RUNALL)) + func testRotateMBy13() { + #expect(rotateCipher("m", shift: 13) == "z") } - func testRotateNBy13WithWrapAroundAlphabet() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("n", shift: 13), "a") + @Test("rotate n by 13 with wrap around alphabet", .enabled(if: RUNALL)) + func testRotateNBy13WithWrapAroundAlphabet() { + #expect(rotateCipher("n", shift: 13) == "a") } - func testRotateCapitalLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("OMG", shift: 5), "TRL") + @Test("rotate capital letters", .enabled(if: RUNALL)) + func testRotateCapitalLetters() { + #expect(rotateCipher("OMG", shift: 5) == "TRL") } - func testRotateSpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("O M G", shift: 5), "T R L") + @Test("rotate spaces", .enabled(if: RUNALL)) + func testRotateSpaces() { + #expect(rotateCipher("O M G", shift: 5) == "T R L") } - func testRotateNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("Testing 1 2 3 testing", shift: 4), "Xiwxmrk 1 2 3 xiwxmrk") + @Test("rotate numbers", .enabled(if: RUNALL)) + func testRotateNumbers() { + #expect(rotateCipher("Testing 1 2 3 testing", shift: 4) == "Xiwxmrk 1 2 3 xiwxmrk") } - func testRotatePunctuation() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(rotateCipher("Let's eat, Grandma!", shift: 21), "Gzo'n zvo, Bmviyhv!") + @Test("rotate punctuation", .enabled(if: RUNALL)) + func testRotatePunctuation() { + #expect(rotateCipher("Let's eat, Grandma!", shift: 21) == "Gzo'n zvo, Bmviyhv!") } - func testRotateAllLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - rotateCipher("The quick brown fox jumps over the lazy dog.", shift: 13), - "Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") + @Test("rotate all letters", .enabled(if: RUNALL)) + func testRotateAllLetters() { + #expect( + rotateCipher("The quick brown fox jumps over the lazy dog.", shift: 13) + == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") } } diff --git a/exercises/practice/run-length-encoding/.meta/template.swift b/exercises/practice/run-length-encoding/.meta/template.swift index c511fb0d5..2753f4a9d 100644 --- a/exercises/practice/run-length-encoding/.meta/template.swift +++ b/exercises/practice/run-length-encoding/.meta/template.swift @@ -1,24 +1,26 @@ -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.property |camelCase}}{{subCases.description |camelCase }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.property |camelCase}}{{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.property |camelCase}}{{subCases.description |camelCase }}() { {%- if subCases.property == "encode" %} - XCTAssertEqual(RunLengthEncoding.encode("{{subCases.input.string}}"), "{{subCases.expected}}") + #expect(RunLengthEncoding.encode("{{subCases.input.string}}") == "{{subCases.expected}}") {%- elif subCases.property == "consistency" %} let encoded = RunLengthEncoding.encode("{{subCases.input.string}}") let decoded = RunLengthEncoding.decode(encoded) - XCTAssertEqual(decoded, "{{subCases.expected}}") + #expect(decoded == "{{subCases.expected}}") {%- else %} - XCTAssertEqual(RunLengthEncoding.decode("{{subCases.input.string}}"), "{{subCases.expected}}") + #expect(RunLengthEncoding.decode("{{subCases.input.string}}") == "{{subCases.expected}}") {%- endif %} } {% endfor -%} diff --git a/exercises/practice/run-length-encoding/Package.swift b/exercises/practice/run-length-encoding/Package.swift index bd3662532..4b0b043a8 100644 --- a/exercises/practice/run-length-encoding/Package.swift +++ b/exercises/practice/run-length-encoding/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/run-length-encoding/Tests/RunLengthEncodingTests/RunLengthEncodingTests.swift b/exercises/practice/run-length-encoding/Tests/RunLengthEncodingTests/RunLengthEncodingTests.swift index 8ed0285aa..9ddd205ac 100644 --- a/exercises/practice/run-length-encoding/Tests/RunLengthEncodingTests/RunLengthEncodingTests.swift +++ b/exercises/practice/run-length-encoding/Tests/RunLengthEncodingTests/RunLengthEncodingTests.swift @@ -1,77 +1,80 @@ -import XCTest +import Foundation +import Testing @testable import RunLengthEncoding -class RunLengthEncodingTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct RunLengthEncodingTests { + + @Test("empty string") func testEncodeEmptyString() { - XCTAssertEqual(RunLengthEncoding.encode(""), "") + #expect(RunLengthEncoding.encode("") == "") } - func testEncodeSingleCharactersOnlyAreEncodedWithoutCount() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.encode("XYZ"), "XYZ") + @Test("single characters only are encoded without count", .enabled(if: RUNALL)) + func testEncodeSingleCharactersOnlyAreEncodedWithoutCount() { + #expect(RunLengthEncoding.encode("XYZ") == "XYZ") } - func testEncodeStringWithNoSingleCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.encode("AABBBCCCC"), "2A3B4C") + @Test("string with no single characters", .enabled(if: RUNALL)) + func testEncodeStringWithNoSingleCharacters() { + #expect(RunLengthEncoding.encode("AABBBCCCC") == "2A3B4C") } - func testEncodeSingleCharactersMixedWithRepeatedCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - RunLengthEncoding.encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"), - "12WB12W3B24WB") + @Test("single characters mixed with repeated characters", .enabled(if: RUNALL)) + func testEncodeSingleCharactersMixedWithRepeatedCharacters() { + #expect( + RunLengthEncoding.encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") + == "12WB12W3B24WB") } - func testEncodeMultipleWhitespaceMixedInString() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.encode(" hsqq qww "), "2 hs2q q2w2 ") + @Test("multiple whitespace mixed in string", .enabled(if: RUNALL)) + func testEncodeMultipleWhitespaceMixedInString() { + #expect(RunLengthEncoding.encode(" hsqq qww ") == "2 hs2q q2w2 ") } - func testEncodeLowercaseCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.encode("aabbbcccc"), "2a3b4c") + @Test("lowercase characters", .enabled(if: RUNALL)) + func testEncodeLowercaseCharacters() { + #expect(RunLengthEncoding.encode("aabbbcccc") == "2a3b4c") } - func testDecodeEmptyString() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.decode(""), "") + @Test("empty string", .enabled(if: RUNALL)) + func testDecodeEmptyString() { + #expect(RunLengthEncoding.decode("") == "") } - func testDecodeSingleCharactersOnly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.decode("XYZ"), "XYZ") + @Test("single characters only", .enabled(if: RUNALL)) + func testDecodeSingleCharactersOnly() { + #expect(RunLengthEncoding.decode("XYZ") == "XYZ") } - func testDecodeStringWithNoSingleCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.decode("2A3B4C"), "AABBBCCCC") + @Test("string with no single characters", .enabled(if: RUNALL)) + func testDecodeStringWithNoSingleCharacters() { + #expect(RunLengthEncoding.decode("2A3B4C") == "AABBBCCCC") } - func testDecodeSingleCharactersWithRepeatedCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - RunLengthEncoding.decode("12WB12W3B24WB"), - "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") + @Test("single characters with repeated characters", .enabled(if: RUNALL)) + func testDecodeSingleCharactersWithRepeatedCharacters() { + #expect( + RunLengthEncoding.decode("12WB12W3B24WB") + == "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") } - func testDecodeMultipleWhitespaceMixedInString() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.decode("2 hs2q q2w2 "), " hsqq qww ") + @Test("multiple whitespace mixed in string", .enabled(if: RUNALL)) + func testDecodeMultipleWhitespaceMixedInString() { + #expect(RunLengthEncoding.decode("2 hs2q q2w2 ") == " hsqq qww ") } - func testDecodeLowercaseString() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(RunLengthEncoding.decode("2a3b4c"), "aabbbcccc") + @Test("lowercase string", .enabled(if: RUNALL)) + func testDecodeLowercaseString() { + #expect(RunLengthEncoding.decode("2a3b4c") == "aabbbcccc") } - func testConsistencyEncodeFollowedByDecodeGivesOriginalString() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("encode followed by decode gives original string", .enabled(if: RUNALL)) + func testConsistencyEncodeFollowedByDecodeGivesOriginalString() { let encoded = RunLengthEncoding.encode("zzz ZZ zZ") let decoded = RunLengthEncoding.decode(encoded) - XCTAssertEqual(decoded, "zzz ZZ zZ") + #expect(decoded == "zzz ZZ zZ") } } diff --git a/exercises/practice/say/.meta/template.swift b/exercises/practice/say/.meta/template.swift index 383af676a..122367779 100644 --- a/exercises/practice/say/.meta/template.swift +++ b/exercises/practice/say/.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 }}() { {%- ifnot case.expected.error -%} - XCTAssertEqual(try! say(number: {{case.input.number}}), "{{case.expected}}") + #expect(try! say(number: {{case.input.number}}) == "{{case.expected}}") {%- else %} - XCTAssertThrowsError(try say(number: {{case.input.number}})) { error in - XCTAssertEqual(error as? SayError, SayError.outOfRange) + #expect(throws: SayError.outOfRange) { + try say(number: {{case.input.number}}) } {%- endif %} } diff --git a/exercises/practice/say/Package.swift b/exercises/practice/say/Package.swift index be232fe3e..1e5bd7e75 100644 --- a/exercises/practice/say/Package.swift +++ b/exercises/practice/say/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/say/Tests/SayTests/SayTests.swift b/exercises/practice/say/Tests/SayTests/SayTests.swift index 5d2e09b72..20e0d4a46 100644 --- a/exercises/practice/say/Tests/SayTests/SayTests.swift +++ b/exercises/practice/say/Tests/SayTests/SayTests.swift @@ -1,110 +1,111 @@ -import XCTest +import Foundation +import Testing @testable import Say -class SayTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct SayTests { + + @Test("zero") func testZero() { - XCTAssertEqual(try! say(number: 0), "zero") + #expect(try! say(number: 0) == "zero") } - func testOne() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1), "one") + @Test("one", .enabled(if: RUNALL)) + func testOne() { + #expect(try! say(number: 1) == "one") } - func testFourteen() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 14), "fourteen") + @Test("fourteen", .enabled(if: RUNALL)) + func testFourteen() { + #expect(try! say(number: 14) == "fourteen") } - func testTwenty() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 20), "twenty") + @Test("twenty", .enabled(if: RUNALL)) + func testTwenty() { + #expect(try! say(number: 20) == "twenty") } - func testTwentyTwo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 22), "twenty-two") + @Test("twenty-two", .enabled(if: RUNALL)) + func testTwentyTwo() { + #expect(try! say(number: 22) == "twenty-two") } - func testThirty() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 30), "thirty") + @Test("thirty", .enabled(if: RUNALL)) + func testThirty() { + #expect(try! say(number: 30) == "thirty") } - func testNinetyNine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 99), "ninety-nine") + @Test("ninety-nine", .enabled(if: RUNALL)) + func testNinetyNine() { + #expect(try! say(number: 99) == "ninety-nine") } - func testOneHundred() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 100), "one hundred") + @Test("one hundred", .enabled(if: RUNALL)) + func testOneHundred() { + #expect(try! say(number: 100) == "one hundred") } - func testOneHundredTwentyThree() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 123), "one hundred twenty-three") + @Test("one hundred twenty-three", .enabled(if: RUNALL)) + func testOneHundredTwentyThree() { + #expect(try! say(number: 123) == "one hundred twenty-three") } - func testTwoHundred() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 200), "two hundred") + @Test("two hundred", .enabled(if: RUNALL)) + func testTwoHundred() { + #expect(try! say(number: 200) == "two hundred") } - func testNineHundredNinetyNine() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 999), "nine hundred ninety-nine") + @Test("nine hundred ninety-nine", .enabled(if: RUNALL)) + func testNineHundredNinetyNine() { + #expect(try! say(number: 999) == "nine hundred ninety-nine") } - func testOneThousand() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1000), "one thousand") + @Test("one thousand", .enabled(if: RUNALL)) + func testOneThousand() { + #expect(try! say(number: 1000) == "one thousand") } - func testOneThousandTwoHundredThirtyFour() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1234), "one thousand two hundred thirty-four") + @Test("one thousand two hundred thirty-four", .enabled(if: RUNALL)) + func testOneThousandTwoHundredThirtyFour() { + #expect(try! say(number: 1234) == "one thousand two hundred thirty-four") } - func testOneMillion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1_000_000), "one million") + @Test("one million", .enabled(if: RUNALL)) + func testOneMillion() { + #expect(try! say(number: 1_000_000) == "one million") } - func testOneMillionTwoThousandThreeHundredFortyFive() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1_002_345), "one million two thousand three hundred forty-five") + @Test("one million two thousand three hundred forty-five", .enabled(if: RUNALL)) + func testOneMillionTwoThousandThreeHundredFortyFive() { + #expect(try! say(number: 1_002_345) == "one million two thousand three hundred forty-five") } - func testOneBillion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(try! say(number: 1_000_000_000), "one billion") + @Test("one billion", .enabled(if: RUNALL)) + func testOneBillion() { + #expect(try! say(number: 1_000_000_000) == "one billion") } - func testABigNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - try! say(number: 987_654_321_123), - "nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three" + @Test("a big number", .enabled(if: RUNALL)) + func testABigNumber() { + #expect( + try! say(number: 987_654_321_123) + == "nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three" ) } - func testNumbersBelowZeroAreOutOfRange() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - - XCTAssertThrowsError(try say(number: -1)) { error in - XCTAssertEqual(error as? SayError, SayError.outOfRange) + @Test("numbers below zero are out of range", .enabled(if: RUNALL)) + func testNumbersBelowZeroAreOutOfRange() { + #expect(throws: SayError.outOfRange) { + try say(number: -1) } } - func testNumbersAbove999999999999AreOutOfRange() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - - XCTAssertThrowsError(try say(number: 1_000_000_000_000)) { error in - XCTAssertEqual(error as? SayError, SayError.outOfRange) + @Test("numbers above 999,999,999,999 are out of range", .enabled(if: RUNALL)) + func testNumbersAbove999999999999AreOutOfRange() { + #expect(throws: SayError.outOfRange) { + try say(number: 1_000_000_000_000) } } }