From 7233261eb14bfc3164037e41a85c9c9a2ed76d61 Mon Sep 17 00:00:00 2001 From: meatball Date: Wed, 18 Dec 2024 16:43:30 +0100 Subject: [PATCH] Update Swift tools version to 6.0 and refactor test templates for consistency --- exercises/practice/bob/.meta/template.swift | 26 +- exercises/practice/bob/.meta/tests.toml | 5 + exercises/practice/bob/Package.swift | 2 +- .../bob/Tests/BobTests/BobTests.swift | 157 ++++----- .../practice/bottle-song/.meta/template.swift | 28 +- exercises/practice/bottle-song/Package.swift | 2 +- .../BottleSongTests/BottleSongTests.swift | 47 +-- .../practice/bowling/.meta/template.swift | 38 ++- exercises/practice/bowling/Package.swift | 2 +- .../Tests/BowlingTests/BowlingTests.swift | 300 ++++++++++-------- .../circular-buffer/.meta/template.swift | 28 +- .../practice/circular-buffer/Package.swift | 2 +- .../CircularBufferTests.swift | 124 ++++---- 13 files changed, 409 insertions(+), 352 deletions(-) diff --git a/exercises/practice/bob/.meta/template.swift b/exercises/practice/bob/.meta/template.swift index 9f3bb77b3..db6b5ce2a 100644 --- a/exercises/practice/bob/.meta/template.swift +++ b/exercises/practice/bob/.meta/template.swift @@ -1,16 +1,18 @@ -import XCTest -@testable import Bob -class BobTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false - +import Testing +import Foundation +@testable import {{exercise|camelCase}} + +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 }}() { - {% else -%} - func test{{case.description | camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - {% endif -%} - XCTAssertEqual("{{case.expected}}", Bob.response("{{case.input.heyBob | inspect}}")) + {% if forloop.first -%} + @Test("{{case.description}}") + {% else -%} + @Test("{{case.description}}", .enabled(if: RUNALL)) + {% endif -%} + func test{{case.description |camelCase }}() { + #expect("{{case.expected}}" == Bob.response("{{case.input.heyBob | inspect}}")) } {% endfor %} } diff --git a/exercises/practice/bob/.meta/tests.toml b/exercises/practice/bob/.meta/tests.toml index ea47d6bb0..5299e2895 100644 --- a/exercises/practice/bob/.meta/tests.toml +++ b/exercises/practice/bob/.meta/tests.toml @@ -71,6 +71,7 @@ description = "alternate silence" [66953780-165b-4e7e-8ce3-4bcb80b6385a] description = "multiple line question" +include = false [5371ef75-d9ea-4103-bcfa-2da973ddec1b] description = "starting with whitespace" @@ -83,3 +84,7 @@ description = "other whitespace" [12983553-8601-46a8-92fa-fcaa3bc4a2a0] description = "non-question ending with whitespace" + +[2c7278ac-f955-4eb4-bf8f-e33eb4116a15] +description = "multiple line question" +reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a" diff --git a/exercises/practice/bob/Package.swift b/exercises/practice/bob/Package.swift index 4ed7cbb5e..c1d773571 100644 --- a/exercises/practice/bob/Package.swift +++ b/exercises/practice/bob/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/bob/Tests/BobTests/BobTests.swift b/exercises/practice/bob/Tests/BobTests/BobTests.swift index a3550a3cb..c3e1a8fd7 100644 --- a/exercises/practice/bob/Tests/BobTests/BobTests.swift +++ b/exercises/practice/bob/Tests/BobTests/BobTests.swift @@ -1,134 +1,135 @@ -import XCTest +import Foundation +import Testing @testable import Bob -class BobTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct BobTests { + + @Test("stating something") func testStatingSomething() { - XCTAssertEqual("Whatever.", Bob.response("Tom-ay-to, tom-aaaah-to.")) + #expect("Whatever." == Bob.response("Tom-ay-to, tom-aaaah-to.")) } - func testShouting() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whoa, chill out!", Bob.response("WATCH OUT!")) + @Test("shouting", .enabled(if: RUNALL)) + func testShouting() { + #expect("Whoa, chill out!" == Bob.response("WATCH OUT!")) } - func testShoutingGibberish() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whoa, chill out!", Bob.response("FCECDFCAAB")) + @Test("shouting gibberish", .enabled(if: RUNALL)) + func testShoutingGibberish() { + #expect("Whoa, chill out!" == Bob.response("FCECDFCAAB")) } - func testAskingAQuestion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("Does this cryogenic chamber make me look fat?")) + @Test("asking a question", .enabled(if: RUNALL)) + func testAskingAQuestion() { + #expect("Sure." == Bob.response("Does this cryogenic chamber make me look fat?")) } - func testAskingANumericQuestion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("You are, what, like 15?")) + @Test("asking a numeric question", .enabled(if: RUNALL)) + func testAskingANumericQuestion() { + #expect("Sure." == Bob.response("You are, what, like 15?")) } - func testAskingGibberish() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("fffbbcbeab?")) + @Test("asking gibberish", .enabled(if: RUNALL)) + func testAskingGibberish() { + #expect("Sure." == Bob.response("fffbbcbeab?")) } - func testTalkingForcefully() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response("Hi there!")) + @Test("talking forcefully", .enabled(if: RUNALL)) + func testTalkingForcefully() { + #expect("Whatever." == Bob.response("Hi there!")) } - func testUsingAcronymsInRegularSpeech() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response("It's OK if you don't want to go work for NASA.")) + @Test("using acronyms in regular speech", .enabled(if: RUNALL)) + func testUsingAcronymsInRegularSpeech() { + #expect("Whatever." == Bob.response("It's OK if you don't want to go work for NASA.")) } - func testForcefulQuestion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Calm down, I know what I'm doing!", Bob.response("WHAT'S GOING ON?")) + @Test("forceful question", .enabled(if: RUNALL)) + func testForcefulQuestion() { + #expect("Calm down, I know what I'm doing!" == Bob.response("WHAT'S GOING ON?")) } - func testShoutingNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whoa, chill out!", Bob.response("1, 2, 3 GO!")) + @Test("shouting numbers", .enabled(if: RUNALL)) + func testShoutingNumbers() { + #expect("Whoa, chill out!" == Bob.response("1, 2, 3 GO!")) } - func testNoLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response("1, 2, 3")) + @Test("no letters", .enabled(if: RUNALL)) + func testNoLetters() { + #expect("Whatever." == Bob.response("1, 2, 3")) } - func testQuestionWithNoLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("4?")) + @Test("question with no letters", .enabled(if: RUNALL)) + func testQuestionWithNoLetters() { + #expect("Sure." == Bob.response("4?")) } - func testShoutingWithSpecialCharacters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "Whoa, chill out!", Bob.response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")) + @Test("shouting with special characters", .enabled(if: RUNALL)) + func testShoutingWithSpecialCharacters() { + #expect("Whoa, chill out!" == Bob.response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")) } - func testShoutingWithNoExclamationMark() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whoa, chill out!", Bob.response("I HATE THE DENTIST")) + @Test("shouting with no exclamation mark", .enabled(if: RUNALL)) + func testShoutingWithNoExclamationMark() { + #expect("Whoa, chill out!" == Bob.response("I HATE THE DENTIST")) } - func testStatementContainingQuestionMark() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response("Ending with ? means a question.")) + @Test("statement containing question mark", .enabled(if: RUNALL)) + func testStatementContainingQuestionMark() { + #expect("Whatever." == Bob.response("Ending with ? means a question.")) } - func testNonLettersWithQuestion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response(":) ?")) + @Test("non-letters with question", .enabled(if: RUNALL)) + func testNonLettersWithQuestion() { + #expect("Sure." == Bob.response(":) ?")) } - func testPrattlingOn() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("Wait! Hang on. Are you going to be OK?")) + @Test("prattling on", .enabled(if: RUNALL)) + func testPrattlingOn() { + #expect("Sure." == Bob.response("Wait! Hang on. Are you going to be OK?")) } - func testSilence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Fine. Be that way!", Bob.response("")) + @Test("silence", .enabled(if: RUNALL)) + func testSilence() { + #expect("Fine. Be that way!" == Bob.response("")) } - func testProlongedSilence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Fine. Be that way!", Bob.response(" ")) + @Test("prolonged silence", .enabled(if: RUNALL)) + func testProlongedSilence() { + #expect("Fine. Be that way!" == Bob.response(" ")) } - func testAlternateSilence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Fine. Be that way!", Bob.response("\t\t\t\t\t\t\t\t\t\t")) + @Test("alternate silence", .enabled(if: RUNALL)) + func testAlternateSilence() { + #expect("Fine. Be that way!" == Bob.response("\t\t\t\t\t\t\t\t\t\t")) } - func testMultipleLineQuestion() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "Whatever.", Bob.response("\nDoes this cryogenic chamber make me look fat?\nNo.")) + @Test("starting with whitespace", .enabled(if: RUNALL)) + func testStartingWithWhitespace() { + #expect("Whatever." == Bob.response(" hmmmmmmm...")) } - func testStartingWithWhitespace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response(" hmmmmmmm...")) + @Test("ending with whitespace", .enabled(if: RUNALL)) + func testEndingWithWhitespace() { + #expect("Sure." == Bob.response("Okay if like my spacebar quite a bit? ")) } - func testEndingWithWhitespace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Sure.", Bob.response("Okay if like my spacebar quite a bit? ")) + @Test("other whitespace", .enabled(if: RUNALL)) + func testOtherWhitespace() { + #expect("Fine. Be that way!" == Bob.response("\n\r \t")) } - func testOtherWhitespace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Fine. Be that way!", Bob.response("\n\r \t")) + @Test("non-question ending with whitespace", .enabled(if: RUNALL)) + func testNonQuestionEndingWithWhitespace() { + #expect("Whatever." == Bob.response("This is a statement ending with whitespace ")) } - func testNonQuestionEndingWithWhitespace() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("Whatever.", Bob.response("This is a statement ending with whitespace ")) + @Test("multiple line question", .enabled(if: RUNALL)) + func testMultipleLineQuestion() { + #expect("Sure." == Bob.response("\nDoes this cryogenic chamber make\n me look fat?")) } } diff --git a/exercises/practice/bottle-song/.meta/template.swift b/exercises/practice/bottle-song/.meta/template.swift index 0706a07e1..932180a2b 100644 --- a/exercises/practice/bottle-song/.meta/template.swift +++ b/exercises/practice/bottle-song/.meta/template.swift @@ -1,33 +1,35 @@ -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 { {% outerOuter: for case in cases %} {%- outer: for subCases in case.cases %} {%- if subCases.cases %} {%- for subSubCases in subCases.cases %} {%- if forloop.outerOuter.first and forloop.outer.first and forloop.first %} - func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() { - {%- else %} - func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - {%- endif %} + @Test("{{subSubCases.description}}") + {%- else %} + @Test("{{subSubCases.description}}", .enabled(if: RUNALL)) + {%- endif %} + func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() { let bottleSong = BottleSong(bottles: {{subSubCases.input.startBottles}}) let expected = {{subSubCases.expected | toStringArray }} - XCTAssertEqual(bottleSong.song(takedown: {{subSubCases.input.takeDown}}), expected) + #expect(bottleSong.song(takedown: {{subSubCases.input.takeDown}}) == expected) } {% endfor -%} {%- else %} {%- if forloop.outerOuter.first and forloop.outer.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 bottleSong = BottleSong(bottles: {{subCases.input.startBottles}}) let expected = {{subCases.expected | toStringArray }} - XCTAssertEqual(bottleSong.song(takedown: {{subCases.input.takeDown}}), expected) + #expect(bottleSong.song(takedown: {{subCases.input.takeDown}}) == expected) } {%- endif %} {% endfor -%} diff --git a/exercises/practice/bottle-song/Package.swift b/exercises/practice/bottle-song/Package.swift index c065ac99e..29cc56062 100644 --- a/exercises/practice/bottle-song/Package.swift +++ b/exercises/practice/bottle-song/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/bottle-song/Tests/BottleSongTests/BottleSongTests.swift b/exercises/practice/bottle-song/Tests/BottleSongTests/BottleSongTests.swift index e80246f69..5627eab3b 100644 --- a/exercises/practice/bottle-song/Tests/BottleSongTests/BottleSongTests.swift +++ b/exercises/practice/bottle-song/Tests/BottleSongTests/BottleSongTests.swift @@ -1,10 +1,13 @@ -import XCTest +import Foundation +import Testing @testable import BottleSong -class BottleSongTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct BottleSongTests { + + @Test("first generic verse") func testFirstGenericVerse1() { let bottleSong = BottleSong(bottles: 10) let expected = [ @@ -12,44 +15,44 @@ class BottleSongTests: XCTestCase { "And if one green bottle should accidentally fall,", "There'll be nine green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 1), expected) + #expect(bottleSong.song(takedown: 1) == expected) } - func testLastGenericVerse1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("last generic verse", .enabled(if: RUNALL)) + func testLastGenericVerse1() { let bottleSong = BottleSong(bottles: 3) let expected = [ "Three green bottles hanging on the wall,", "Three green bottles hanging on the wall,", "And if one green bottle should accidentally fall,", "There'll be two green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 1), expected) + #expect(bottleSong.song(takedown: 1) == expected) } - func testVerseWith2Bottles1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("verse with 2 bottles", .enabled(if: RUNALL)) + func testVerseWith2Bottles1() { let bottleSong = BottleSong(bottles: 2) let expected = [ "Two green bottles hanging on the wall,", "Two green bottles hanging on the wall,", "And if one green bottle should accidentally fall,", "There'll be one green bottle hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 1), expected) + #expect(bottleSong.song(takedown: 1) == expected) } - func testVerseWith1Bottle1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("verse with 1 bottle", .enabled(if: RUNALL)) + func testVerseWith1Bottle1() { let bottleSong = BottleSong(bottles: 1) let expected = [ "One green bottle hanging on the wall,", "One green bottle hanging on the wall,", "And if one green bottle should accidentally fall,", "There'll be no green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 1), expected) + #expect(bottleSong.song(takedown: 1) == expected) } - func testFirstTwoVerses1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("first two verses", .enabled(if: RUNALL)) + func testFirstTwoVerses1() { let bottleSong = BottleSong(bottles: 10) let expected = [ "Ten green bottles hanging on the wall,", "Ten green bottles hanging on the wall,", @@ -59,11 +62,11 @@ class BottleSongTests: XCTestCase { "And if one green bottle should accidentally fall,", "There'll be eight green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 2), expected) + #expect(bottleSong.song(takedown: 2) == expected) } - func testLastThreeVerses1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("last three verses", .enabled(if: RUNALL)) + func testLastThreeVerses1() { let bottleSong = BottleSong(bottles: 3) let expected = [ "Three green bottles hanging on the wall,", "Three green bottles hanging on the wall,", @@ -76,11 +79,11 @@ class BottleSongTests: XCTestCase { "And if one green bottle should accidentally fall,", "There'll be no green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 3), expected) + #expect(bottleSong.song(takedown: 3) == expected) } - func testAllVerses1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("all verses", .enabled(if: RUNALL)) + func testAllVerses1() { let bottleSong = BottleSong(bottles: 10) let expected = [ "Ten green bottles hanging on the wall,", "Ten green bottles hanging on the wall,", @@ -114,7 +117,7 @@ class BottleSongTests: XCTestCase { "And if one green bottle should accidentally fall,", "There'll be no green bottles hanging on the wall.", ] - XCTAssertEqual(bottleSong.song(takedown: 10), expected) + #expect(bottleSong.song(takedown: 10) == expected) } } diff --git a/exercises/practice/bowling/.meta/template.swift b/exercises/practice/bowling/.meta/template.swift index d5cacd829..2c8244655 100644 --- a/exercises/practice/bowling/.meta/template.swift +++ b/exercises/practice/bowling/.meta/template.swift @@ -1,41 +1,45 @@ -import XCTest +import Foundation +import Testing + @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 bowling = Bowling({{case.input.previousRolls}}) {% if case.property == "score" -%} {% if case.expected.error -%} - XCTAssertThrowsError(try bowling.{{case.property}}()) { error in + #expect(throws: {% if case.expected.error == "Score cannot be taken until the end of the game" -%} - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) + BowlingError.gameInProgress {% else -%} - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) + BowlingError.tooManyPinsInFrame {% endif -%} - } + ) {try bowling.{{case.property}}()} {% else -%} - XCTAssertEqual(try! bowling.{{case.property}}(), {{case.expected}}) + #expect(try! bowling.{{case.property}}() == {{case.expected}}) {% endif -%} {% else -%} {% if case.expected.error -%} - XCTAssertThrowsError(try bowling.{{case.property}}(pins: {{case.input.roll}})) { error in + #expect(throws: {%- if case.expected.error == "Negative roll is invalid" %} - XCTAssertEqual(error as? BowlingError, BowlingError.negativePins) + BowlingError.negativePins {%- elif case.expected.error == "Pin count exceeds pins on the lane" %} - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) + BowlingError.tooManyPinsInFrame {%- else %} - XCTAssertEqual(error as? BowlingError, BowlingError.gameIsOver) + BowlingError.gameIsOver {%- endif %} - } + ) {try bowling.{{case.property}}(pins: {{case.input.roll}})} + {% else -%} - XCTAssertEqual(try! bowling.{{case.property}}(pins: {{case.input.roll}}), {{case.expected}}) + #expect(try! bowling.{{case.property}}(pins: {{case.input.roll}}) == {{case.expected}}) {% endif -%} {% endif -%} } diff --git a/exercises/practice/bowling/Package.swift b/exercises/practice/bowling/Package.swift index 3bd26a812..e80dc7f33 100644 --- a/exercises/practice/bowling/Package.swift +++ b/exercises/practice/bowling/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/bowling/Tests/BowlingTests/BowlingTests.swift b/exercises/practice/bowling/Tests/BowlingTests/BowlingTests.swift index 6f5a0d25d..73701e0d7 100644 --- a/exercises/practice/bowling/Tests/BowlingTests/BowlingTests.swift +++ b/exercises/practice/bowling/Tests/BowlingTests/BowlingTests.swift @@ -1,224 +1,272 @@ -import XCTest +import Foundation +import Testing @testable import Bowling -class BowlingTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "true"]) ?? false +@Suite struct BowlingTests { + + @Test("should be able to score a game with all zeros") func testShouldBeAbleToScoreAGameWithAllZeros() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 0) + #expect(try! bowling.score() == 0) } - func testShouldBeAbleToScoreAGameWithNoStrikesOrSpares() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("should be able to score a game with no strikes or spares", .enabled(if: RUNALL)) + func testShouldBeAbleToScoreAGameWithNoStrikesOrSpares() { let bowling = Bowling([3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6]) - XCTAssertEqual(try! bowling.score(), 90) + #expect(try! bowling.score() == 90) } - func testASpareFollowedByZerosIsWorthTenPoints() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a spare followed by zeros is worth ten points", .enabled(if: RUNALL)) + func testASpareFollowedByZerosIsWorthTenPoints() { let bowling = Bowling([6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 10) + #expect(try! bowling.score() == 10) } - func testPointsScoredInTheRollAfterASpareAreCountedTwice() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("points scored in the roll after a spare are counted twice", .enabled(if: RUNALL)) + func testPointsScoredInTheRollAfterASpareAreCountedTwice() { let bowling = Bowling([6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 16) + #expect(try! bowling.score() == 16) } - func testConsecutiveSparesEachGetAOneRollBonus() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("consecutive spares each get a one roll bonus", .enabled(if: RUNALL)) + func testConsecutiveSparesEachGetAOneRollBonus() { let bowling = Bowling([5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 31) + #expect(try! bowling.score() == 31) } - func testASpareInTheLastFrameGetsAOneRollBonusThatIsCountedOnce() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "a spare in the last frame gets a one roll bonus that is counted once", .enabled(if: RUNALL)) + func testASpareInTheLastFrameGetsAOneRollBonusThatIsCountedOnce() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 7]) - XCTAssertEqual(try! bowling.score(), 17) + #expect(try! bowling.score() == 17) } - func testAStrikeEarnsTenPointsInAFrameWithASingleRoll() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a strike earns ten points in a frame with a single roll", .enabled(if: RUNALL)) + func testAStrikeEarnsTenPointsInAFrameWithASingleRoll() { let bowling = Bowling([10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 10) + #expect(try! bowling.score() == 10) } - func testPointsScoredInTheTwoRollsAfterAStrikeAreCountedTwiceAsABonus() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "points scored in the two rolls after a strike are counted twice as a bonus", + .enabled(if: RUNALL)) + func testPointsScoredInTheTwoRollsAfterAStrikeAreCountedTwiceAsABonus() { let bowling = Bowling([10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 26) + #expect(try! bowling.score() == 26) } - func testConsecutiveStrikesEachGetTheTwoRollBonus() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("consecutive strikes each get the two roll bonus", .enabled(if: RUNALL)) + func testConsecutiveStrikesEachGetTheTwoRollBonus() { let bowling = Bowling([10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertEqual(try! bowling.score(), 81) + #expect(try! bowling.score() == 81) } - func testAStrikeInTheLastFrameGetsATwoRollBonusThatIsCountedOnce() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "a strike in the last frame gets a two roll bonus that is counted once", .enabled(if: RUNALL)) + func testAStrikeInTheLastFrameGetsATwoRollBonusThatIsCountedOnce() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1]) - XCTAssertEqual(try! bowling.score(), 18) + #expect(try! bowling.score() == 18) } - func testRollingASpareWithTheTwoRollBonusDoesNotGetABonusRoll() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("rolling a spare with the two roll bonus does not get a bonus roll", .enabled(if: RUNALL)) + func testRollingASpareWithTheTwoRollBonusDoesNotGetABonusRoll() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 3]) - XCTAssertEqual(try! bowling.score(), 20) + #expect(try! bowling.score() == 20) } - func testStrikesWithTheTwoRollBonusDoNotGetBonusRolls() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("strikes with the two roll bonus do not get bonus rolls", .enabled(if: RUNALL)) + func testStrikesWithTheTwoRollBonusDoNotGetBonusRolls() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10]) - XCTAssertEqual(try! bowling.score(), 30) + #expect(try! bowling.score() == 30) } - func testLastTwoStrikesFollowedByOnlyLastBonusWithNonStrikePoints() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("last two strikes followed by only last bonus with non strike points", .enabled(if: RUNALL)) + func testLastTwoStrikesFollowedByOnlyLastBonusWithNonStrikePoints() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 0, 1]) - XCTAssertEqual(try! bowling.score(), 31) + #expect(try! bowling.score() == 31) } - func testAStrikeWithTheOneRollBonusAfterASpareInTheLastFrameDoesNotGetABonus() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "a strike with the one roll bonus after a spare in the last frame does not get a bonus", + .enabled(if: RUNALL)) + func testAStrikeWithTheOneRollBonusAfterASpareInTheLastFrameDoesNotGetABonus() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 10]) - XCTAssertEqual(try! bowling.score(), 20) + #expect(try! bowling.score() == 20) } - func testAllStrikesIsAPerfectGame() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("all strikes is a perfect game", .enabled(if: RUNALL)) + func testAllStrikesIsAPerfectGame() { let bowling = Bowling([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) - XCTAssertEqual(try! bowling.score(), 300) + #expect(try! bowling.score() == 300) } - func testRollsCannotScoreNegativePoints() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("rolls cannot score negative points", .enabled(if: RUNALL)) + func testRollsCannotScoreNegativePoints() { let bowling = Bowling([]) - XCTAssertThrowsError(try bowling.roll(pins: -1)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.negativePins) - } + #expect( + throws: + BowlingError.negativePins + ) { try bowling.roll(pins: -1) } + } - func testARollCannotScoreMoreThan10Points() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a roll cannot score more than 10 points", .enabled(if: RUNALL)) + func testARollCannotScoreMoreThan10Points() { let bowling = Bowling([]) - XCTAssertThrowsError(try bowling.roll(pins: 11)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 11) } + } - func testTwoRollsInAFrameCannotScoreMoreThan10Points() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("two rolls in a frame cannot score more than 10 points", .enabled(if: RUNALL)) + func testTwoRollsInAFrameCannotScoreMoreThan10Points() { let bowling = Bowling([5]) - XCTAssertThrowsError(try bowling.roll(pins: 6)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 6) } + } - func testBonusRollAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "bonus roll after a strike in the last frame cannot score more than 10 points", + .enabled(if: RUNALL)) + func testBonusRollAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]) - XCTAssertThrowsError(try bowling.roll(pins: 11)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 11) } + } - func testTwoBonusRollsAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "two bonus rolls after a strike in the last frame cannot score more than 10 points", + .enabled(if: RUNALL)) + func testTwoBonusRollsAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5]) - XCTAssertThrowsError(try bowling.roll(pins: 6)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 6) } + } - func testTwoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOneIsAStrike() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike", + .enabled(if: RUNALL)) + func testTwoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOneIsAStrike() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 6]) - XCTAssertEqual(try! bowling.score(), 26) + #expect(try! bowling.score() == 26) } - func testTheSecondBonusRollsAfterAStrikeInTheLastFrameCannotBeAStrikeIfTheFirstOneIsNotAStrike() - throws - { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "the second bonus rolls after a strike in the last frame cannot be a strike if the first one is not a strike", + .enabled(if: RUNALL)) + func testTheSecondBonusRollsAfterAStrikeInTheLastFrameCannotBeAStrikeIfTheFirstOneIsNotAStrike() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6]) - XCTAssertThrowsError(try bowling.roll(pins: 10)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 10) } + } - func testSecondBonusRollAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "second bonus roll after a strike in the last frame cannot score more than 10 points", + .enabled(if: RUNALL)) + func testSecondBonusRollAfterAStrikeInTheLastFrameCannotScoreMoreThan10Points() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10]) - XCTAssertThrowsError(try bowling.roll(pins: 11)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.tooManyPinsInFrame) - } + #expect( + throws: + BowlingError.tooManyPinsInFrame + ) { try bowling.roll(pins: 11) } + } - func testAnUnstartedGameCannotBeScored() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("an unstarted game cannot be scored", .enabled(if: RUNALL)) + func testAnUnstartedGameCannotBeScored() { let bowling = Bowling([]) - XCTAssertThrowsError(try bowling.score()) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) - } + #expect( + throws: + BowlingError.gameInProgress + ) { try bowling.score() } } - func testAnIncompleteGameCannotBeScored() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("an incomplete game cannot be scored", .enabled(if: RUNALL)) + func testAnIncompleteGameCannotBeScored() { let bowling = Bowling([0, 0]) - XCTAssertThrowsError(try bowling.score()) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) - } + #expect( + throws: + BowlingError.gameInProgress + ) { try bowling.score() } } - func testCannotRollIfGameAlreadyHasTenFrames() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("cannot roll if game already has ten frames", .enabled(if: RUNALL)) + func testCannotRollIfGameAlreadyHasTenFrames() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - XCTAssertThrowsError(try bowling.roll(pins: 0)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameIsOver) - } + #expect( + throws: + BowlingError.gameIsOver + ) { try bowling.roll(pins: 0) } + } - func testBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "bonus rolls for a strike in the last frame must be rolled before score can be calculated", + .enabled(if: RUNALL)) + func testBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]) - XCTAssertThrowsError(try bowling.score()) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) - } + #expect( + throws: + BowlingError.gameInProgress + ) { try bowling.score() } } - func testBothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "both bonus rolls for a strike in the last frame must be rolled before score can be calculated", + .enabled(if: RUNALL)) + func testBothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10]) - XCTAssertThrowsError(try bowling.score()) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) - } + #expect( + throws: + BowlingError.gameInProgress + ) { try bowling.score() } } - func testBonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "bonus roll for a spare in the last frame must be rolled before score can be calculated", + .enabled(if: RUNALL)) + func testBonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3]) - XCTAssertThrowsError(try bowling.score()) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameInProgress) - } + #expect( + throws: + BowlingError.gameInProgress + ) { try bowling.score() } } - func testCannotRollAfterBonusRollForSpare() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("cannot roll after bonus roll for spare", .enabled(if: RUNALL)) + func testCannotRollAfterBonusRollForSpare() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 2]) - XCTAssertThrowsError(try bowling.roll(pins: 2)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameIsOver) - } + #expect( + throws: + BowlingError.gameIsOver + ) { try bowling.roll(pins: 2) } + } - func testCannotRollAfterBonusRollsForStrike() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("cannot roll after bonus rolls for strike", .enabled(if: RUNALL)) + func testCannotRollAfterBonusRollsForStrike() { let bowling = Bowling([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 3, 2]) - XCTAssertThrowsError(try bowling.roll(pins: 2)) { error in - XCTAssertEqual(error as? BowlingError, BowlingError.gameIsOver) - } + #expect( + throws: + BowlingError.gameIsOver + ) { try bowling.roll(pins: 2) } + } } diff --git a/exercises/practice/circular-buffer/.meta/template.swift b/exercises/practice/circular-buffer/.meta/template.swift index 0703cffe8..a7f130367 100644 --- a/exercises/practice/circular-buffer/.meta/template.swift +++ b/exercises/practice/circular-buffer/.meta/template.swift @@ -1,30 +1,28 @@ -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 -%} + {% if forloop.first -%} + @Test("{{case.description}}") + {% else -%} + @Test("{{case.description}}", .enabled(if: RUNALL)) + {% endif -%} func test{{case.description |camelCase }}() { - {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - {% endif -%} var buffer = CircularBuffer(capacity: {{ case.input.capacity }}) {% for operation in case.input.operations %} {%- if operation.operation == "read" %} {%- ifnot operation.should_succeed %} - XCTAssertThrowsError(try buffer.read()) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferEmpty) - } + #expect(throws: CircularBufferError.bufferEmpty) {try buffer.read()} {%- else %} - XCTAssertEqual(try! buffer.read(), {{ operation.expected }}) + #expect(try! buffer.read() == {{ operation.expected }}) {%- endif %} {%- elif operation.operation == "write" %} {%- ifnot operation.should_succeed %} - XCTAssertThrowsError(try buffer.write({{ operation.item }})) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferFull) - } + #expect(throws: CircularBufferError.bufferFull) {try buffer.write({{ operation.item }})} {%- else %} try! buffer.write({{ operation.item }}) {%- endif %} diff --git a/exercises/practice/circular-buffer/Package.swift b/exercises/practice/circular-buffer/Package.swift index 6a818b21b..65086b0c6 100644 --- a/exercises/practice/circular-buffer/Package.swift +++ b/exercises/practice/circular-buffer/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift b/exercises/practice/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift index 3b02d3ced..85db89d27 100644 --- a/exercises/practice/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift +++ b/exercises/practice/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift @@ -1,147 +1,143 @@ -import XCTest +import Foundation +import Testing @testable import CircularBuffer -class CircularBufferTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "true"]) ?? false +@Suite struct CircularBufferTests { + + @Test("reading empty buffer should fail") func testReadingEmptyBufferShouldFail() { var buffer = CircularBuffer(capacity: 1) - XCTAssertThrowsError(try buffer.read()) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferEmpty) - } + #expect(throws: CircularBufferError.bufferEmpty) { try buffer.read() } } - func testCanReadAnItemJustWritten() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("can read an item just written", .enabled(if: RUNALL)) + func testCanReadAnItemJustWritten() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) - XCTAssertEqual(try! buffer.read(), 1) + #expect(try! buffer.read() == 1) } - func testEachItemMayOnlyBeReadOnce() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("each item may only be read once", .enabled(if: RUNALL)) + func testEachItemMayOnlyBeReadOnce() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) - XCTAssertEqual(try! buffer.read(), 1) - XCTAssertThrowsError(try buffer.read()) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferEmpty) - } + #expect(try! buffer.read() == 1) + #expect(throws: CircularBufferError.bufferEmpty) { try buffer.read() } } - func testItemsAreReadInTheOrderTheyAreWritten() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("items are read in the order they are written", .enabled(if: RUNALL)) + func testItemsAreReadInTheOrderTheyAreWritten() { var buffer = CircularBuffer(capacity: 2) try! buffer.write(1) try! buffer.write(2) - XCTAssertEqual(try! buffer.read(), 1) - XCTAssertEqual(try! buffer.read(), 2) + #expect(try! buffer.read() == 1) + #expect(try! buffer.read() == 2) } - func testFullBufferCantBeWrittenTo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("full buffer can't be written to", .enabled(if: RUNALL)) + func testFullBufferCantBeWrittenTo() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) - XCTAssertThrowsError(try buffer.write(2)) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferFull) - } + #expect(throws: CircularBufferError.bufferFull) { try buffer.write(2) } } - func testAReadFreesUpCapacityForAnotherWrite() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a read frees up capacity for another write", .enabled(if: RUNALL)) + func testAReadFreesUpCapacityForAnotherWrite() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) - XCTAssertEqual(try! buffer.read(), 1) + #expect(try! buffer.read() == 1) try! buffer.write(2) - XCTAssertEqual(try! buffer.read(), 2) + #expect(try! buffer.read() == 2) } - func testReadPositionIsMaintainedEvenAcrossMultipleWrites() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("read position is maintained even across multiple writes", .enabled(if: RUNALL)) + func testReadPositionIsMaintainedEvenAcrossMultipleWrites() { var buffer = CircularBuffer(capacity: 3) try! buffer.write(1) try! buffer.write(2) - XCTAssertEqual(try! buffer.read(), 1) + #expect(try! buffer.read() == 1) try! buffer.write(3) - XCTAssertEqual(try! buffer.read(), 2) - XCTAssertEqual(try! buffer.read(), 3) + #expect(try! buffer.read() == 2) + #expect(try! buffer.read() == 3) } - func testItemsClearedOutOfBufferCantBeRead() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("items cleared out of buffer can't be read", .enabled(if: RUNALL)) + func testItemsClearedOutOfBufferCantBeRead() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) buffer.clear() - XCTAssertThrowsError(try buffer.read()) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferEmpty) - } + #expect(throws: CircularBufferError.bufferEmpty) { try buffer.read() } } - func testClearFreesUpCapacityForAnotherWrite() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("clear frees up capacity for another write", .enabled(if: RUNALL)) + func testClearFreesUpCapacityForAnotherWrite() { var buffer = CircularBuffer(capacity: 1) try! buffer.write(1) buffer.clear() try! buffer.write(2) - XCTAssertEqual(try! buffer.read(), 2) + #expect(try! buffer.read() == 2) } - func testClearDoesNothingOnEmptyBuffer() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("clear does nothing on empty buffer", .enabled(if: RUNALL)) + func testClearDoesNothingOnEmptyBuffer() { var buffer = CircularBuffer(capacity: 1) buffer.clear() try! buffer.write(1) - XCTAssertEqual(try! buffer.read(), 1) + #expect(try! buffer.read() == 1) } - func testOverwriteActsLikeWriteOnNonFullBuffer() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("overwrite acts like write on non-full buffer", .enabled(if: RUNALL)) + func testOverwriteActsLikeWriteOnNonFullBuffer() { var buffer = CircularBuffer(capacity: 2) try! buffer.write(1) buffer.overwrite(2) - XCTAssertEqual(try! buffer.read(), 1) - XCTAssertEqual(try! buffer.read(), 2) + #expect(try! buffer.read() == 1) + #expect(try! buffer.read() == 2) } - func testOverwriteReplacesTheOldestItemOnFullBuffer() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("overwrite replaces the oldest item on full buffer", .enabled(if: RUNALL)) + func testOverwriteReplacesTheOldestItemOnFullBuffer() { var buffer = CircularBuffer(capacity: 2) try! buffer.write(1) try! buffer.write(2) buffer.overwrite(3) - XCTAssertEqual(try! buffer.read(), 2) - XCTAssertEqual(try! buffer.read(), 3) + #expect(try! buffer.read() == 2) + #expect(try! buffer.read() == 3) } - func testOverwriteReplacesTheOldestItemRemainingInBufferFollowingARead() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "overwrite replaces the oldest item remaining in buffer following a read", .enabled(if: RUNALL)) + func testOverwriteReplacesTheOldestItemRemainingInBufferFollowingARead() { var buffer = CircularBuffer(capacity: 3) try! buffer.write(1) try! buffer.write(2) try! buffer.write(3) - XCTAssertEqual(try! buffer.read(), 1) + #expect(try! buffer.read() == 1) try! buffer.write(4) buffer.overwrite(5) - XCTAssertEqual(try! buffer.read(), 3) - XCTAssertEqual(try! buffer.read(), 4) - XCTAssertEqual(try! buffer.read(), 5) + #expect(try! buffer.read() == 3) + #expect(try! buffer.read() == 4) + #expect(try! buffer.read() == 5) } - func testInitialClearDoesNotAffectWrappingAround() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("initial clear does not affect wrapping around", .enabled(if: RUNALL)) + func testInitialClearDoesNotAffectWrappingAround() { var buffer = CircularBuffer(capacity: 2) buffer.clear() @@ -149,10 +145,8 @@ class CircularBufferTests: XCTestCase { try! buffer.write(2) buffer.overwrite(3) buffer.overwrite(4) - XCTAssertEqual(try! buffer.read(), 3) - XCTAssertEqual(try! buffer.read(), 4) - XCTAssertThrowsError(try buffer.read()) { error in - XCTAssertEqual(error as? CircularBufferError, .bufferEmpty) - } + #expect(try! buffer.read() == 3) + #expect(try! buffer.read() == 4) + #expect(throws: CircularBufferError.bufferEmpty) { try buffer.read() } } }