From ceca707c592b8eb28e915d39841066ecc3cefe9e Mon Sep 17 00:00:00 2001 From: meatball Date: Wed, 18 Dec 2024 12:05:25 +0100 Subject: [PATCH] Update Swift tools version to 6.0 and modify test templates for consistency --- .../practice/allergies/.meta/template.swift | 20 +- exercises/practice/allergies/Package.swift | 2 +- .../Tests/AllergiesTests/AllergiesTests.swift | 313 +++++++++--------- .../practice/anagram/.meta/template.swift | 20 +- exercises/practice/anagram/.meta/tests.toml | 16 + exercises/practice/anagram/Package.swift | 2 +- .../Tests/AnagramTests/AnagramTests.swift | 115 ++++--- .../atbash-cipher/.docs/instructions.md | 2 +- .../practice/atbash-cipher/.meta/config.json | 2 +- .../atbash-cipher/.meta/template.swift | 18 +- .../practice/atbash-cipher/Package.swift | 2 +- .../AtbashCipherTests/AtbashCipherTests.swift | 100 +++--- .../binary-search/.meta/template.swift | 29 +- .../practice/binary-search/Package.swift | 2 +- .../BinarySearchTests/BinarySearchTests.swift | 81 +++-- 15 files changed, 382 insertions(+), 342 deletions(-) diff --git a/exercises/practice/allergies/.meta/template.swift b/exercises/practice/allergies/.meta/template.swift index 06358adcc..343292ddf 100644 --- a/exercises/practice/allergies/.meta/template.swift +++ b/exercises/practice/allergies/.meta/template.swift @@ -1,26 +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 { {% outer: for case in cases %} {%- for subCases in case.cases %} {%- if forloop.outer.first and forloop.first %} - func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() { + @Test("{{subCases.description}}") {%- else %} - func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{subCases.description}}", .enabled(if: RUNALL)) {%- endif %} + func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() { let allergies = Allergies({{subCases.input.score}}) {%- if subCases.property == "allergicTo" %} {%- if subCases.expected %} - XCTAssertTrue(allergies.{{subCases.property}}(item: "{{subCases.input.item}}")) + #expect(allergies.{{subCases.property}}(item: "{{subCases.input.item}}")) {%- else %} - XCTAssertFalse(allergies.{{subCases.property}}(item: "{{subCases.input.item}}")) + #expect(!allergies.{{subCases.property}}(item: "{{subCases.input.item}}")) {%- endif %} {%- else %} {%- if subCases.expected %} - XCTAssertEqual(allergies.{{subCases.property}}(), {{subCases.expected | toStringArray }}) + #expect(allergies.{{subCases.property}}() == {{subCases.expected | toStringArray }}) {%- endif %} {%- endif %} } diff --git a/exercises/practice/allergies/Package.swift b/exercises/practice/allergies/Package.swift index bc8178a57..80cec5a94 100644 --- a/exercises/practice/allergies/Package.swift +++ b/exercises/practice/allergies/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/allergies/Tests/AllergiesTests/AllergiesTests.swift b/exercises/practice/allergies/Tests/AllergiesTests/AllergiesTests.swift index c35a15a88..5f3f9e584 100644 --- a/exercises/practice/allergies/Tests/AllergiesTests/AllergiesTests.swift +++ b/exercises/practice/allergies/Tests/AllergiesTests/AllergiesTests.swift @@ -1,309 +1,314 @@ -import XCTest +import Foundation +import Testing @testable import Allergies -class AllergiesTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct AllergiesTests { + + @Test("not allergic to anything") func testNotAllergicToAnything1() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "eggs")) + #expect(!allergies.allergicTo(item: "eggs")) } - func testAllergicOnlyToEggs1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to eggs", .enabled(if: RUNALL)) + func testAllergicOnlyToEggs1() { let allergies = Allergies(1) - XCTAssertTrue(allergies.allergicTo(item: "eggs")) + #expect(allergies.allergicTo(item: "eggs")) } - func testAllergicToEggsAndSomethingElse1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to eggs and something else", .enabled(if: RUNALL)) + func testAllergicToEggsAndSomethingElse1() { let allergies = Allergies(3) - XCTAssertTrue(allergies.allergicTo(item: "eggs")) + #expect(allergies.allergicTo(item: "eggs")) } - func testAllergicToSomethingButNotEggs1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not eggs", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotEggs1() { let allergies = Allergies(2) - XCTAssertFalse(allergies.allergicTo(item: "eggs")) + #expect(!allergies.allergicTo(item: "eggs")) } - func testAllergicToEverything1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything1() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "eggs")) + #expect(allergies.allergicTo(item: "eggs")) } - func testNotAllergicToAnything2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything2() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "peanuts")) + #expect(!allergies.allergicTo(item: "peanuts")) } - func testAllergicOnlyToPeanuts2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to peanuts", .enabled(if: RUNALL)) + func testAllergicOnlyToPeanuts2() { let allergies = Allergies(2) - XCTAssertTrue(allergies.allergicTo(item: "peanuts")) + #expect(allergies.allergicTo(item: "peanuts")) } - func testAllergicToPeanutsAndSomethingElse2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to peanuts and something else", .enabled(if: RUNALL)) + func testAllergicToPeanutsAndSomethingElse2() { let allergies = Allergies(7) - XCTAssertTrue(allergies.allergicTo(item: "peanuts")) + #expect(allergies.allergicTo(item: "peanuts")) } - func testAllergicToSomethingButNotPeanuts2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not peanuts", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotPeanuts2() { let allergies = Allergies(5) - XCTAssertFalse(allergies.allergicTo(item: "peanuts")) + #expect(!allergies.allergicTo(item: "peanuts")) } - func testAllergicToEverything2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything2() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "peanuts")) + #expect(allergies.allergicTo(item: "peanuts")) } - func testNotAllergicToAnything3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything3() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "shellfish")) + #expect(!allergies.allergicTo(item: "shellfish")) } - func testAllergicOnlyToShellfish3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to shellfish", .enabled(if: RUNALL)) + func testAllergicOnlyToShellfish3() { let allergies = Allergies(4) - XCTAssertTrue(allergies.allergicTo(item: "shellfish")) + #expect(allergies.allergicTo(item: "shellfish")) } - func testAllergicToShellfishAndSomethingElse3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to shellfish and something else", .enabled(if: RUNALL)) + func testAllergicToShellfishAndSomethingElse3() { let allergies = Allergies(14) - XCTAssertTrue(allergies.allergicTo(item: "shellfish")) + #expect(allergies.allergicTo(item: "shellfish")) } - func testAllergicToSomethingButNotShellfish3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not shellfish", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotShellfish3() { let allergies = Allergies(10) - XCTAssertFalse(allergies.allergicTo(item: "shellfish")) + #expect(!allergies.allergicTo(item: "shellfish")) } - func testAllergicToEverything3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything3() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "shellfish")) + #expect(allergies.allergicTo(item: "shellfish")) } - func testNotAllergicToAnything4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything4() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "strawberries")) + #expect(!allergies.allergicTo(item: "strawberries")) } - func testAllergicOnlyToStrawberries4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to strawberries", .enabled(if: RUNALL)) + func testAllergicOnlyToStrawberries4() { let allergies = Allergies(8) - XCTAssertTrue(allergies.allergicTo(item: "strawberries")) + #expect(allergies.allergicTo(item: "strawberries")) } - func testAllergicToStrawberriesAndSomethingElse4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to strawberries and something else", .enabled(if: RUNALL)) + func testAllergicToStrawberriesAndSomethingElse4() { let allergies = Allergies(28) - XCTAssertTrue(allergies.allergicTo(item: "strawberries")) + #expect(allergies.allergicTo(item: "strawberries")) } - func testAllergicToSomethingButNotStrawberries4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not strawberries", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotStrawberries4() { let allergies = Allergies(20) - XCTAssertFalse(allergies.allergicTo(item: "strawberries")) + #expect(!allergies.allergicTo(item: "strawberries")) } - func testAllergicToEverything4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything4() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "strawberries")) + #expect(allergies.allergicTo(item: "strawberries")) } - func testNotAllergicToAnything5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything5() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "tomatoes")) + #expect(!allergies.allergicTo(item: "tomatoes")) } - func testAllergicOnlyToTomatoes5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to tomatoes", .enabled(if: RUNALL)) + func testAllergicOnlyToTomatoes5() { let allergies = Allergies(16) - XCTAssertTrue(allergies.allergicTo(item: "tomatoes")) + #expect(allergies.allergicTo(item: "tomatoes")) } - func testAllergicToTomatoesAndSomethingElse5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to tomatoes and something else", .enabled(if: RUNALL)) + func testAllergicToTomatoesAndSomethingElse5() { let allergies = Allergies(56) - XCTAssertTrue(allergies.allergicTo(item: "tomatoes")) + #expect(allergies.allergicTo(item: "tomatoes")) } - func testAllergicToSomethingButNotTomatoes5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not tomatoes", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotTomatoes5() { let allergies = Allergies(40) - XCTAssertFalse(allergies.allergicTo(item: "tomatoes")) + #expect(!allergies.allergicTo(item: "tomatoes")) } - func testAllergicToEverything5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything5() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "tomatoes")) + #expect(allergies.allergicTo(item: "tomatoes")) } - func testNotAllergicToAnything6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything6() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "chocolate")) + #expect(!allergies.allergicTo(item: "chocolate")) } - func testAllergicOnlyToChocolate6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to chocolate", .enabled(if: RUNALL)) + func testAllergicOnlyToChocolate6() { let allergies = Allergies(32) - XCTAssertTrue(allergies.allergicTo(item: "chocolate")) + #expect(allergies.allergicTo(item: "chocolate")) } - func testAllergicToChocolateAndSomethingElse6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to chocolate and something else", .enabled(if: RUNALL)) + func testAllergicToChocolateAndSomethingElse6() { let allergies = Allergies(112) - XCTAssertTrue(allergies.allergicTo(item: "chocolate")) + #expect(allergies.allergicTo(item: "chocolate")) } - func testAllergicToSomethingButNotChocolate6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not chocolate", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotChocolate6() { let allergies = Allergies(80) - XCTAssertFalse(allergies.allergicTo(item: "chocolate")) + #expect(!allergies.allergicTo(item: "chocolate")) } - func testAllergicToEverything6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything6() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "chocolate")) + #expect(allergies.allergicTo(item: "chocolate")) } - func testNotAllergicToAnything7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything7() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "pollen")) + #expect(!allergies.allergicTo(item: "pollen")) } - func testAllergicOnlyToPollen7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to pollen", .enabled(if: RUNALL)) + func testAllergicOnlyToPollen7() { let allergies = Allergies(64) - XCTAssertTrue(allergies.allergicTo(item: "pollen")) + #expect(allergies.allergicTo(item: "pollen")) } - func testAllergicToPollenAndSomethingElse7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to pollen and something else", .enabled(if: RUNALL)) + func testAllergicToPollenAndSomethingElse7() { let allergies = Allergies(224) - XCTAssertTrue(allergies.allergicTo(item: "pollen")) + #expect(allergies.allergicTo(item: "pollen")) } - func testAllergicToSomethingButNotPollen7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not pollen", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotPollen7() { let allergies = Allergies(160) - XCTAssertFalse(allergies.allergicTo(item: "pollen")) + #expect(!allergies.allergicTo(item: "pollen")) } - func testAllergicToEverything7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything7() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "pollen")) + #expect(allergies.allergicTo(item: "pollen")) } - func testNotAllergicToAnything8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("not allergic to anything", .enabled(if: RUNALL)) + func testNotAllergicToAnything8() { let allergies = Allergies(0) - XCTAssertFalse(allergies.allergicTo(item: "cats")) + #expect(!allergies.allergicTo(item: "cats")) } - func testAllergicOnlyToCats8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic only to cats", .enabled(if: RUNALL)) + func testAllergicOnlyToCats8() { let allergies = Allergies(128) - XCTAssertTrue(allergies.allergicTo(item: "cats")) + #expect(allergies.allergicTo(item: "cats")) } - func testAllergicToCatsAndSomethingElse8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to cats and something else", .enabled(if: RUNALL)) + func testAllergicToCatsAndSomethingElse8() { let allergies = Allergies(192) - XCTAssertTrue(allergies.allergicTo(item: "cats")) + #expect(allergies.allergicTo(item: "cats")) } - func testAllergicToSomethingButNotCats8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to something, but not cats", .enabled(if: RUNALL)) + func testAllergicToSomethingButNotCats8() { let allergies = Allergies(64) - XCTAssertFalse(allergies.allergicTo(item: "cats")) + #expect(!allergies.allergicTo(item: "cats")) } - func testAllergicToEverything8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("allergic to everything", .enabled(if: RUNALL)) + func testAllergicToEverything8() { let allergies = Allergies(255) - XCTAssertTrue(allergies.allergicTo(item: "cats")) + #expect(allergies.allergicTo(item: "cats")) } - func testNoAllergies9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("no allergies", .enabled(if: RUNALL)) + func testNoAllergies9() { let allergies = Allergies(0) } - func testJustEggs9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("just eggs", .enabled(if: RUNALL)) + func testJustEggs9() { let allergies = Allergies(1) - XCTAssertEqual(allergies.list(), ["eggs"]) + #expect(allergies.list() == ["eggs"]) } - func testJustPeanuts9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("just peanuts", .enabled(if: RUNALL)) + func testJustPeanuts9() { let allergies = Allergies(2) - XCTAssertEqual(allergies.list(), ["peanuts"]) + #expect(allergies.list() == ["peanuts"]) } - func testJustStrawberries9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("just strawberries", .enabled(if: RUNALL)) + func testJustStrawberries9() { let allergies = Allergies(8) - XCTAssertEqual(allergies.list(), ["strawberries"]) + #expect(allergies.list() == ["strawberries"]) } - func testEggsAndPeanuts9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("eggs and peanuts", .enabled(if: RUNALL)) + func testEggsAndPeanuts9() { let allergies = Allergies(3) - XCTAssertEqual(allergies.list(), ["eggs", "peanuts"]) + #expect(allergies.list() == ["eggs", "peanuts"]) } - func testMoreThanEggsButNotPeanuts9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("more than eggs but not peanuts", .enabled(if: RUNALL)) + func testMoreThanEggsButNotPeanuts9() { let allergies = Allergies(5) - XCTAssertEqual(allergies.list(), ["eggs", "shellfish"]) + #expect(allergies.list() == ["eggs", "shellfish"]) } - func testLotsOfStuff9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("lots of stuff", .enabled(if: RUNALL)) + func testLotsOfStuff9() { let allergies = Allergies(248) - XCTAssertEqual(allergies.list(), ["strawberries", "tomatoes", "chocolate", "pollen", "cats"]) + #expect(allergies.list() == ["strawberries", "tomatoes", "chocolate", "pollen", "cats"]) } - func testEverything9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("everything", .enabled(if: RUNALL)) + func testEverything9() { let allergies = Allergies(255) - XCTAssertEqual( - allergies.list(), - ["eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"]) + #expect( + allergies.list() == [ + "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats", + ]) } - func testNoAllergenScoreParts9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("no allergen score parts", .enabled(if: RUNALL)) + func testNoAllergenScoreParts9() { let allergies = Allergies(509) - XCTAssertEqual( - allergies.list(), - ["eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"]) + #expect( + allergies.list() == [ + "eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats", + ]) } - func testNoAllergenScorePartsWithoutHighestValidScore9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("no allergen score parts without highest valid score", .enabled(if: RUNALL)) + func testNoAllergenScorePartsWithoutHighestValidScore9() { let allergies = Allergies(257) - XCTAssertEqual(allergies.list(), ["eggs"]) + #expect(allergies.list() == ["eggs"]) } } diff --git a/exercises/practice/anagram/.meta/template.swift b/exercises/practice/anagram/.meta/template.swift index 2beebb50d..154ad81f8 100644 --- a/exercises/practice/anagram/.meta/template.swift +++ b/exercises/practice/anagram/.meta/template.swift @@ -1,15 +1,17 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} - {% if forloop.first %} + {% 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 -%} let anagram = {{exercise|camelCase}}(word: "{{case.input.subject}}") let results = anagram.match({{case.input.candidates | toStringArray }}) {%- if case.expected %} @@ -17,7 +19,7 @@ class {{exercise|camelCase}}Tests: XCTestCase { {%- else %} let expected = [String]() {%- endif %} - XCTAssertEqual(results, expected) + #expect(results == expected) } {% endfor -%} } diff --git a/exercises/practice/anagram/.meta/tests.toml b/exercises/practice/anagram/.meta/tests.toml index 5141eaf67..0265e730d 100644 --- a/exercises/practice/anagram/.meta/tests.toml +++ b/exercises/practice/anagram/.meta/tests.toml @@ -46,10 +46,18 @@ description = "detects anagrams using case-insensitive possible matches" [7cc195ad-e3c7-44ee-9fd2-d3c344806a2c] description = "does not detect an anagram if the original word is repeated" +include = false + +[630abb71-a94e-4715-8395-179ec1df9f91] +description = "does not detect an anagram if the original word is repeated" +reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c" [9878a1c9-d6ea-4235-ae51-3ea2befd6842] description = "anagrams must use all letters exactly once" +[85757361-4535-45fd-ac0e-3810d40debc1] +description = "words are not anagrams of themselves (case-insensitive)" + [68934ed0-010b-4ef9-857a-20c9012d1ebf] description = "words are not anagrams of themselves" reimplements = "85757361-4535-45fd-ac0e-3810d40debc1" @@ -69,3 +77,11 @@ include = false [33d3f67e-fbb9-49d3-a90e-0beb00861da7] description = "words other than themselves can be anagrams" reimplements = "a0705568-628c-4b55-9798-82e4acde51ca" + +[a6854f66-eec1-4afd-a137-62ef2870c051] +description = "handles case of greek letters" +include = false + +[fd3509e5-e3ba-409d-ac3d-a9ac84d13296] +description = "different characters may have the same bytes" +include = false diff --git a/exercises/practice/anagram/Package.swift b/exercises/practice/anagram/Package.swift index 0aae7d190..46e7258ff 100644 --- a/exercises/practice/anagram/Package.swift +++ b/exercises/practice/anagram/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/anagram/Tests/AnagramTests/AnagramTests.swift b/exercises/practice/anagram/Tests/AnagramTests/AnagramTests.swift index 56134b7fa..bb4d87d2f 100644 --- a/exercises/practice/anagram/Tests/AnagramTests/AnagramTests.swift +++ b/exercises/practice/anagram/Tests/AnagramTests/AnagramTests.swift @@ -1,134 +1,149 @@ -import XCTest +import Foundation +import Testing @testable import Anagram -class AnagramTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct AnagramTests { + + @Test("no matches") func testNoMatches() { let anagram = Anagram(word: "diaper") let results = anagram.match(["hello", "world", "zombies", "pants"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsTwoAnagrams() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects two anagrams", .enabled(if: RUNALL)) + func testDetectsTwoAnagrams() { let anagram = Anagram(word: "solemn") let results = anagram.match(["lemons", "cherry", "melons"]) let expected = ["lemons", "melons"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDoesNotDetectAnagramSubsets() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("does not detect anagram subsets", .enabled(if: RUNALL)) + func testDoesNotDetectAnagramSubsets() { let anagram = Anagram(word: "good") let results = anagram.match(["dog", "goody"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsAnagram() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects anagram", .enabled(if: RUNALL)) + func testDetectsAnagram() { let anagram = Anagram(word: "listen") let results = anagram.match(["enlists", "google", "inlets", "banana"]) let expected = ["inlets"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsThreeAnagrams() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects three anagrams", .enabled(if: RUNALL)) + func testDetectsThreeAnagrams() { let anagram = Anagram(word: "allergy") let results = anagram.match(["gallery", "ballerina", "regally", "clergy", "largely", "leading"]) let expected = ["gallery", "regally", "largely"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsMultipleAnagramsWithDifferentCase() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects multiple anagrams with different case", .enabled(if: RUNALL)) + func testDetectsMultipleAnagramsWithDifferentCase() { let anagram = Anagram(word: "nose") let results = anagram.match(["Eons", "ONES"]) let expected = ["Eons", "ONES"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDoesNotDetectNonAnagramsWithIdenticalChecksum() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("does not detect non-anagrams with identical checksum", .enabled(if: RUNALL)) + func testDoesNotDetectNonAnagramsWithIdenticalChecksum() { let anagram = Anagram(word: "mass") let results = anagram.match(["last"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsAnagramsCaseInsensitively() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects anagrams case-insensitively", .enabled(if: RUNALL)) + func testDetectsAnagramsCaseInsensitively() { let anagram = Anagram(word: "Orchestra") let results = anagram.match(["cashregister", "Carthorse", "radishes"]) let expected = ["Carthorse"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsAnagramsUsingCaseInsensitiveSubject() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects anagrams using case-insensitive subject", .enabled(if: RUNALL)) + func testDetectsAnagramsUsingCaseInsensitiveSubject() { let anagram = Anagram(word: "Orchestra") let results = anagram.match(["cashregister", "carthorse", "radishes"]) let expected = ["carthorse"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDetectsAnagramsUsingCaseInsensitivePossibleMatches() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("detects anagrams using case-insensitive possible matches", .enabled(if: RUNALL)) + func testDetectsAnagramsUsingCaseInsensitivePossibleMatches() { let anagram = Anagram(word: "orchestra") let results = anagram.match(["cashregister", "Carthorse", "radishes"]) let expected = ["Carthorse"] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testDoesNotDetectAnAnagramIfTheOriginalWordIsRepeated() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("does not detect an anagram if the original word is repeated", .enabled(if: RUNALL)) + func testDoesNotDetectAnAnagramIfTheOriginalWordIsRepeated() { let anagram = Anagram(word: "go") - let results = anagram.match(["go Go GO"]) + let results = anagram.match(["goGoGO"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testAnagramsMustUseAllLettersExactlyOnce() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("anagrams must use all letters exactly once", .enabled(if: RUNALL)) + func testAnagramsMustUseAllLettersExactlyOnce() { let anagram = Anagram(word: "tapper") let results = anagram.match(["patter"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) + } + + @Test("words are not anagrams of themselves (case-insensitive)", .enabled(if: RUNALL)) + func testWordsAreNotAnagramsOfThemselvesCaseInsensitive() { + let anagram = Anagram(word: "BANANA") + let results = anagram.match(["BANANA", "Banana", "banana"]) + let expected = [String]() + #expect(results == expected) } - func testWordsAreNotAnagramsOfThemselves() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("words are not anagrams of themselves", .enabled(if: RUNALL)) + func testWordsAreNotAnagramsOfThemselves() { let anagram = Anagram(word: "BANANA") let results = anagram.match(["BANANA"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDifferent() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "words are not anagrams of themselves even if letter case is partially different", + .enabled(if: RUNALL)) + func testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDifferent() { let anagram = Anagram(word: "BANANA") let results = anagram.match(["Banana"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDifferent() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "words are not anagrams of themselves even if letter case is completely different", + .enabled(if: RUNALL)) + func testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDifferent() { let anagram = Anagram(word: "BANANA") let results = anagram.match(["banana"]) let expected = [String]() - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testWordsOtherThanThemselvesCanBeAnagrams() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("words other than themselves can be anagrams", .enabled(if: RUNALL)) + func testWordsOtherThanThemselvesCanBeAnagrams() { let anagram = Anagram(word: "LISTEN") let results = anagram.match(["LISTEN", "Silent"]) let expected = ["Silent"] - XCTAssertEqual(results, expected) + #expect(results == expected) } } diff --git a/exercises/practice/atbash-cipher/.docs/instructions.md b/exercises/practice/atbash-cipher/.docs/instructions.md index 21ca2ce0a..1e7627b1e 100644 --- a/exercises/practice/atbash-cipher/.docs/instructions.md +++ b/exercises/practice/atbash-cipher/.docs/instructions.md @@ -1,6 +1,6 @@ # Instructions -Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East. +Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East. The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards. The first letter is replaced with the last letter, the second with the second-last, and so on. diff --git a/exercises/practice/atbash-cipher/.meta/config.json b/exercises/practice/atbash-cipher/.meta/config.json index a4eb15584..d5aaf6694 100644 --- a/exercises/practice/atbash-cipher/.meta/config.json +++ b/exercises/practice/atbash-cipher/.meta/config.json @@ -24,7 +24,7 @@ ".meta/Sources/AtbashCipher/AtbashCipherExample.swift" ] }, - "blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.", + "blurb": "Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East.", "source": "Wikipedia", "source_url": "https://en.wikipedia.org/wiki/Atbash" } diff --git a/exercises/practice/atbash-cipher/.meta/template.swift b/exercises/practice/atbash-cipher/.meta/template.swift index ddfec0000..32db0353c 100644 --- a/exercises/practice/atbash-cipher/.meta/template.swift +++ b/exercises/practice/atbash-cipher/.meta/template.swift @@ -1,21 +1,23 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {%- for subCases in case.cases %} {% if forloop.first -%} - func test{{subCases.description |camelCase }}() { + @Test("{{subCases.description}}") {% else -%} - func test{{subCases.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{subCases.description}}", .enabled(if: RUNALL)) {% endif -%} + func test{{subCases.description |camelCase }}() { {%- if subCases.property == "encode" -%} - XCTAssertEqual("{{subCases.expected}}", AtbashCipher.encode("{{subCases.input.phrase}}")) + #expect("{{subCases.expected}}" == AtbashCipher.encode("{{subCases.input.phrase}}")) {%- else -%} - XCTAssertEqual("{{subCases.expected}}", AtbashCipher.decode("{{subCases.input.phrase}}")) + #expect("{{subCases.expected}}" == AtbashCipher.decode("{{subCases.input.phrase}}")) {%- endif %} } {%- endfor %} diff --git a/exercises/practice/atbash-cipher/Package.swift b/exercises/practice/atbash-cipher/Package.swift index fd03be4bc..dbfa9ebf7 100644 --- a/exercises/practice/atbash-cipher/Package.swift +++ b/exercises/practice/atbash-cipher/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/atbash-cipher/Tests/AtbashCipherTests/AtbashCipherTests.swift b/exercises/practice/atbash-cipher/Tests/AtbashCipherTests/AtbashCipherTests.swift index 94c3a8de9..a5e34febb 100644 --- a/exercises/practice/atbash-cipher/Tests/AtbashCipherTests/AtbashCipherTests.swift +++ b/exercises/practice/atbash-cipher/Tests/AtbashCipherTests/AtbashCipherTests.swift @@ -1,82 +1,86 @@ -import XCTest +import Foundation +import Testing @testable import AtbashCipher -class AtbashCipherTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct AtbashCipherTests { + + @Test("encode yes") func testEncodeYes() { - XCTAssertEqual("bvh", AtbashCipher.encode("yes")) + #expect("bvh" == AtbashCipher.encode("yes")) } - func testEncodeNo() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("ml", AtbashCipher.encode("no")) + @Test("encode no", .enabled(if: RUNALL)) + func testEncodeNo() { + #expect("ml" == AtbashCipher.encode("no")) } - func testEncodeOmg() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("lnt", AtbashCipher.encode("OMG")) + @Test("encode OMG", .enabled(if: RUNALL)) + func testEncodeOmg() { + #expect("lnt" == AtbashCipher.encode("OMG")) } - func testEncodeSpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("lnt", AtbashCipher.encode("O M G")) + @Test("encode spaces", .enabled(if: RUNALL)) + func testEncodeSpaces() { + #expect("lnt" == AtbashCipher.encode("O M G")) } - func testEncodeMindblowingly() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("nrmwy oldrm tob", AtbashCipher.encode("mindblowingly")) + @Test("encode mindblowingly", .enabled(if: RUNALL)) + func testEncodeMindblowingly() { + #expect("nrmwy oldrm tob" == AtbashCipher.encode("mindblowingly")) } - func testEncodeNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("gvhgr mt123 gvhgr mt", AtbashCipher.encode("Testing,1 2 3, testing.")) + @Test("encode numbers", .enabled(if: RUNALL)) + func testEncodeNumbers() { + #expect("gvhgr mt123 gvhgr mt" == AtbashCipher.encode("Testing,1 2 3, testing.")) } - func testEncodeDeepThought() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("gifgs rhurx grlm", AtbashCipher.encode("Truth is fiction.")) + @Test("encode deep thought", .enabled(if: RUNALL)) + func testEncodeDeepThought() { + #expect("gifgs rhurx grlm" == AtbashCipher.encode("Truth is fiction.")) } - func testEncodeAllTheLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", - AtbashCipher.encode("The quick brown fox jumps over the lazy dog.")) + @Test("encode all the letters", .enabled(if: RUNALL)) + func testEncodeAllTheLetters() { + #expect( + "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" + == AtbashCipher.encode("The quick brown fox jumps over the lazy dog.")) } + @Test("decode exercism") func testDecodeExercism() { - XCTAssertEqual("exercism", AtbashCipher.decode("vcvix rhn")) + #expect("exercism" == AtbashCipher.decode("vcvix rhn")) } - func testDecodeASentence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "anobstacleisoftenasteppingstone", - AtbashCipher.decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v")) + @Test("decode a sentence", .enabled(if: RUNALL)) + func testDecodeASentence() { + #expect( + "anobstacleisoftenasteppingstone" + == AtbashCipher.decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v")) } - func testDecodeNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("testing123testing", AtbashCipher.decode("gvhgr mt123 gvhgr mt")) + @Test("decode numbers", .enabled(if: RUNALL)) + func testDecodeNumbers() { + #expect("testing123testing" == AtbashCipher.decode("gvhgr mt123 gvhgr mt")) } - func testDecodeAllTheLetters() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "thequickbrownfoxjumpsoverthelazydog", - AtbashCipher.decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")) + @Test("decode all the letters", .enabled(if: RUNALL)) + func testDecodeAllTheLetters() { + #expect( + "thequickbrownfoxjumpsoverthelazydog" + == AtbashCipher.decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")) } - func testDecodeWithTooManySpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual("exercism", AtbashCipher.decode("vc vix r hn")) + @Test("decode with too many spaces", .enabled(if: RUNALL)) + func testDecodeWithTooManySpaces() { + #expect("exercism" == AtbashCipher.decode("vc vix r hn")) } - func testDecodeWithNoSpaces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - "anobstacleisoftenasteppingstone", AtbashCipher.decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv")) + @Test("decode with no spaces", .enabled(if: RUNALL)) + func testDecodeWithNoSpaces() { + #expect( + "anobstacleisoftenasteppingstone" == AtbashCipher.decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv")) } } diff --git a/exercises/practice/binary-search/.meta/template.swift b/exercises/practice/binary-search/.meta/template.swift index e5dd0c436..30861e82c 100644 --- a/exercises/practice/binary-search/.meta/template.swift +++ b/exercises/practice/binary-search/.meta/template.swift @@ -1,23 +1,24 @@ -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 -%} - let binarySearch = BinarySearch({{case.input.array}}) - {% if case.expected.error %} - XCTAssertThrowsError(try binarySearch.searchFor({{case.input.value}})) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } - {%- else -%} - XCTAssertEqual(try! binarySearch.searchFor({{case.input.value}}), {{case.expected}}) - {%- endif -%} + func test{{case.description |camelCase }}() { + let binarySearch = BinarySearch({{case.input.array}}) + {% if case.expected.error %} + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor({{case.input.value}})} + + {%- else -%} + #expect(try! binarySearch.searchFor({{case.input.value}}) == {{case.expected}}) + {%- endif -%} } {% endfor -%} } diff --git a/exercises/practice/binary-search/Package.swift b/exercises/practice/binary-search/Package.swift index 45076d750..9a7b79741 100644 --- a/exercises/practice/binary-search/Package.swift +++ b/exercises/practice/binary-search/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/binary-search/Tests/BinarySearchTests/BinarySearchTests.swift b/exercises/practice/binary-search/Tests/BinarySearchTests/BinarySearchTests.swift index faccd0b05..aab70dabe 100644 --- a/exercises/practice/binary-search/Tests/BinarySearchTests/BinarySearchTests.swift +++ b/exercises/practice/binary-search/Tests/BinarySearchTests/BinarySearchTests.swift @@ -1,87 +1,80 @@ -import XCTest +import Foundation +import Testing @testable import BinarySearch -class BinarySearchTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct BinarySearchTests { + + @Test("finds a value in an array with one element") func testFindsAValueInAnArrayWithOneElement() { let binarySearch = BinarySearch([6]) - XCTAssertEqual(try! binarySearch.searchFor(6), 0) + #expect(try! binarySearch.searchFor(6) == 0) } - func testFindsAValueInTheMiddleOfAnArray() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("finds a value in the middle of an array", .enabled(if: RUNALL)) + func testFindsAValueInTheMiddleOfAnArray() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertEqual(try! binarySearch.searchFor(6), 3) + #expect(try! binarySearch.searchFor(6) == 3) } - func testFindsAValueAtTheBeginningOfAnArray() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("finds a value at the beginning of an array", .enabled(if: RUNALL)) + func testFindsAValueAtTheBeginningOfAnArray() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertEqual(try! binarySearch.searchFor(1), 0) + #expect(try! binarySearch.searchFor(1) == 0) } - func testFindsAValueAtTheEndOfAnArray() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("finds a value at the end of an array", .enabled(if: RUNALL)) + func testFindsAValueAtTheEndOfAnArray() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertEqual(try! binarySearch.searchFor(11), 6) + #expect(try! binarySearch.searchFor(11) == 6) } - func testFindsAValueInAnArrayOfOddLength() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("finds a value in an array of odd length", .enabled(if: RUNALL)) + func testFindsAValueInAnArrayOfOddLength() { let binarySearch = BinarySearch([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634]) - XCTAssertEqual(try! binarySearch.searchFor(144), 9) + #expect(try! binarySearch.searchFor(144) == 9) } - func testFindsAValueInAnArrayOfEvenLength() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("finds a value in an array of even length", .enabled(if: RUNALL)) + func testFindsAValueInAnArrayOfEvenLength() { let binarySearch = BinarySearch([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]) - XCTAssertEqual(try! binarySearch.searchFor(21), 5) + #expect(try! binarySearch.searchFor(21) == 5) } - func testIdentifiesThatAValueIsNotIncludedInTheArray() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("identifies that a value is not included in the array", .enabled(if: RUNALL)) + func testIdentifiesThatAValueIsNotIncludedInTheArray() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertThrowsError(try binarySearch.searchFor(7)) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor(7) } } - func testAValueSmallerThanTheArraysSmallestValueIsNotFound() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a value smaller than the array's smallest value is not found", .enabled(if: RUNALL)) + func testAValueSmallerThanTheArraysSmallestValueIsNotFound() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertThrowsError(try binarySearch.searchFor(0)) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor(0) } } - func testAValueLargerThanTheArraysLargestValueIsNotFound() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("a value larger than the array's largest value is not found", .enabled(if: RUNALL)) + func testAValueLargerThanTheArraysLargestValueIsNotFound() { let binarySearch = BinarySearch([1, 3, 4, 6, 8, 9, 11]) - XCTAssertThrowsError(try binarySearch.searchFor(13)) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor(13) } } - func testNothingIsFoundInAnEmptyArray() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("nothing is found in an empty array", .enabled(if: RUNALL)) + func testNothingIsFoundInAnEmptyArray() { let binarySearch = BinarySearch([]) - XCTAssertThrowsError(try binarySearch.searchFor(1)) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor(1) } } - func testNothingIsFoundWhenTheLeftAndRightBoundsCross() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("nothing is found when the left and right bounds cross", .enabled(if: RUNALL)) + func testNothingIsFoundWhenTheLeftAndRightBoundsCross() { let binarySearch = BinarySearch([1, 2]) - XCTAssertThrowsError(try binarySearch.searchFor(0)) { error in - XCTAssertEqual(error as? BinarySearchError, BinarySearchError.valueNotFound) - } + #expect(throws: BinarySearchError.valueNotFound) { try binarySearch.searchFor(0) } } }