diff --git a/exercises/practice/nucleotide-count/.meta/template.swift b/exercises/practice/nucleotide-count/.meta/template.swift index f521e3798..2ee43575e 100644 --- a/exercises/practice/nucleotide-count/.meta/template.swift +++ b/exercises/practice/nucleotide-count/.meta/template.swift @@ -1,24 +1,26 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% 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 }}() { {% if case.expected.error -%} - XCTAssertThrowsError(try DNA(strand: "{{case.input.strand}}")) { error in - XCTAssertEqual(error as? NucleotideCountErrors, NucleotideCountErrors.invalidNucleotide) + #expect(throws: NucleotideCountErrors.invalidNucleotide) { + try DNA(strand: "{{case.input.strand}}") } {% else -%} let dna = try! DNA(strand: "{{case.input.strand}}") let results = dna.counts() let expected = {{case.expected | toStringDictionary}} - XCTAssertEqual(results, expected) + #expect(results == expected) {% endif -%} } {% endfor -%} diff --git a/exercises/practice/nucleotide-count/Package.swift b/exercises/practice/nucleotide-count/Package.swift index 4a77a66f1..a74ffa2af 100644 --- a/exercises/practice/nucleotide-count/Package.swift +++ b/exercises/practice/nucleotide-count/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/nucleotide-count/Tests/NucleotideCountTests/NucleotideCountTests.swift b/exercises/practice/nucleotide-count/Tests/NucleotideCountTests/NucleotideCountTests.swift index 4eb982c72..9beb34ef4 100644 --- a/exercises/practice/nucleotide-count/Tests/NucleotideCountTests/NucleotideCountTests.swift +++ b/exercises/practice/nucleotide-count/Tests/NucleotideCountTests/NucleotideCountTests.swift @@ -1,46 +1,49 @@ -import XCTest +import Foundation +import Testing @testable import NucleotideCount -class NucleotideCountTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct NucleotideCountTests { + + @Test("empty strand") func testEmptyStrand() { let dna = try! DNA(strand: "") let results = dna.counts() let expected = ["A": 0, "C": 0, "G": 0, "T": 0] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testCanCountOneNucleotideInSingleCharacterInput() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("can count one nucleotide in single-character input", .enabled(if: RUNALL)) + func testCanCountOneNucleotideInSingleCharacterInput() { let dna = try! DNA(strand: "G") let results = dna.counts() let expected = ["A": 0, "C": 0, "G": 1, "T": 0] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testStrandWithRepeatedNucleotide() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("strand with repeated nucleotide", .enabled(if: RUNALL)) + func testStrandWithRepeatedNucleotide() { let dna = try! DNA(strand: "GGGGGGG") let results = dna.counts() let expected = ["A": 0, "C": 0, "G": 7, "T": 0] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testStrandWithMultipleNucleotides() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("strand with multiple nucleotides", .enabled(if: RUNALL)) + func testStrandWithMultipleNucleotides() { let dna = try! DNA( strand: "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") let results = dna.counts() let expected = ["A": 20, "C": 12, "G": 17, "T": 21] - XCTAssertEqual(results, expected) + #expect(results == expected) } - func testStrandWithInvalidNucleotides() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try DNA(strand: "AGXXACT")) { error in - XCTAssertEqual(error as? NucleotideCountErrors, NucleotideCountErrors.invalidNucleotide) + @Test("strand with invalid nucleotides", .enabled(if: RUNALL)) + func testStrandWithInvalidNucleotides() { + #expect(throws: NucleotideCountErrors.invalidNucleotide) { + try DNA(strand: "AGXXACT") } } } diff --git a/exercises/practice/ocr-numbers/.meta/template.swift b/exercises/practice/ocr-numbers/.meta/template.swift index d410385f6..567aac88c 100644 --- a/exercises/practice/ocr-numbers/.meta/template.swift +++ b/exercises/practice/ocr-numbers/.meta/template.swift @@ -1,22 +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 -%} + func test{{case.description |camelCase }}() { let input = {{case.input.rows | toStringArray}} {% if case.expected.error -%} - XCTAssertThrowsError(try OcrNumber.convert(rows: input)) { - XCTAssertEqual($0 as? OcrNumberError, .invalidInput) + #expect(throws: OcrNumberError.invalidInput) { + try OcrNumber.convert(rows: input) } {% else -%} - XCTAssertEqual(try! OcrNumber.convert(rows: input), "{{case.expected}}") + #expect(try! OcrNumber.convert(rows: input) == "{{case.expected}}") {% endif -%} } {% endfor -%} diff --git a/exercises/practice/ocr-numbers/Package.swift b/exercises/practice/ocr-numbers/Package.swift index c345f4438..54f50e45e 100644 --- a/exercises/practice/ocr-numbers/Package.swift +++ b/exercises/practice/ocr-numbers/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/ocr-numbers/Tests/OcrNumbersTests/OcrNumbersTests.swift b/exercises/practice/ocr-numbers/Tests/OcrNumbersTests/OcrNumbersTests.swift index ec02a5a72..b9b32cc37 100644 --- a/exercises/practice/ocr-numbers/Tests/OcrNumbersTests/OcrNumbersTests.swift +++ b/exercises/practice/ocr-numbers/Tests/OcrNumbersTests/OcrNumbersTests.swift @@ -1,124 +1,133 @@ -import XCTest +import Foundation +import Testing @testable import OcrNumbers -class OcrNumbersTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct OcrNumbersTests { + + @Test("Recognizes 0") func testRecognizes0() { let input = [" _ ", "| |", "|_|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "0") + #expect(try! OcrNumber.convert(rows: input) == "0") } - func testRecognizes1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 1", .enabled(if: RUNALL)) + func testRecognizes1() { let input = [" ", " |", " |", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "1") + #expect(try! OcrNumber.convert(rows: input) == "1") } - func testUnreadableButCorrectlySizedInputsReturn() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Unreadable but correctly sized inputs return ?", .enabled(if: RUNALL)) + func testUnreadableButCorrectlySizedInputsReturn() { let input = [" ", " _", " |", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "?") + #expect(try! OcrNumber.convert(rows: input) == "?") } - func testInputWithANumberOfLinesThatIsNotAMultipleOfFourRaisesAnError() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "Input with a number of lines that is not a multiple of four raises an error", + .enabled(if: RUNALL)) + func testInputWithANumberOfLinesThatIsNotAMultipleOfFourRaisesAnError() { let input = [" _ ", "| |", " "] - XCTAssertThrowsError(try OcrNumber.convert(rows: input)) { - XCTAssertEqual($0 as? OcrNumberError, .invalidInput) + #expect(throws: OcrNumberError.invalidInput) { + try OcrNumber.convert(rows: input) } } - func testInputWithANumberOfColumnsThatIsNotAMultipleOfThreeRaisesAnError() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "Input with a number of columns that is not a multiple of three raises an error", + .enabled(if: RUNALL)) + func testInputWithANumberOfColumnsThatIsNotAMultipleOfThreeRaisesAnError() { let input = [" ", " |", " |", " "] - XCTAssertThrowsError(try OcrNumber.convert(rows: input)) { - XCTAssertEqual($0 as? OcrNumberError, .invalidInput) + #expect(throws: OcrNumberError.invalidInput) { + try OcrNumber.convert(rows: input) } } - func testRecognizes110101100() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 110101100", .enabled(if: RUNALL)) + func testRecognizes110101100() { let input = [ " _ _ _ _ ", " | || | || | | || || |", " | ||_| ||_| | ||_||_|", " ", ] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "110101100") + #expect(try! OcrNumber.convert(rows: input) == "110101100") } - func testGarbledNumbersInAStringAreReplacedWith() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Garbled numbers in a string are replaced with ?", .enabled(if: RUNALL)) + func testGarbledNumbersInAStringAreReplacedWith() { let input = [ " _ _ _ ", " | || | || | || || |", " | | _| ||_| | ||_||_|", " ", ] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "11?10?1?0") + #expect(try! OcrNumber.convert(rows: input) == "11?10?1?0") } - func testRecognizes2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 2", .enabled(if: RUNALL)) + func testRecognizes2() { let input = [" _ ", " _|", "|_ ", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "2") + #expect(try! OcrNumber.convert(rows: input) == "2") } - func testRecognizes3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 3", .enabled(if: RUNALL)) + func testRecognizes3() { let input = [" _ ", " _|", " _|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "3") + #expect(try! OcrNumber.convert(rows: input) == "3") } - func testRecognizes4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 4", .enabled(if: RUNALL)) + func testRecognizes4() { let input = [" ", "|_|", " |", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "4") + #expect(try! OcrNumber.convert(rows: input) == "4") } - func testRecognizes5() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 5", .enabled(if: RUNALL)) + func testRecognizes5() { let input = [" _ ", "|_ ", " _|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "5") + #expect(try! OcrNumber.convert(rows: input) == "5") } - func testRecognizes6() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 6", .enabled(if: RUNALL)) + func testRecognizes6() { let input = [" _ ", "|_ ", "|_|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "6") + #expect(try! OcrNumber.convert(rows: input) == "6") } - func testRecognizes7() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 7", .enabled(if: RUNALL)) + func testRecognizes7() { let input = [" _ ", " |", " |", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "7") + #expect(try! OcrNumber.convert(rows: input) == "7") } - func testRecognizes8() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 8", .enabled(if: RUNALL)) + func testRecognizes8() { let input = [" _ ", "|_|", "|_|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "8") + #expect(try! OcrNumber.convert(rows: input) == "8") } - func testRecognizes9() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes 9", .enabled(if: RUNALL)) + func testRecognizes9() { let input = [" _ ", "|_|", " _|", " "] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "9") + #expect(try! OcrNumber.convert(rows: input) == "9") } - func testRecognizesStringOfDecimalNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("Recognizes string of decimal numbers", .enabled(if: RUNALL)) + func testRecognizesStringOfDecimalNumbers() { let input = [ " _ _ _ _ _ _ _ _ ", " | _| _||_||_ |_ ||_||_|| |", " ||_ _| | _||_| ||_| _||_|", " ", ] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "1234567890") + #expect(try! OcrNumber.convert(rows: input) == "1234567890") } - func testNumbersSeparatedByEmptyLinesAreRecognizedLinesAreJoinedByCommas() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test( + "Numbers separated by empty lines are recognized. Lines are joined by commas.", + .enabled(if: RUNALL)) + func testNumbersSeparatedByEmptyLinesAreRecognizedLinesAreJoinedByCommas() { let input = [ " _ _ ", " | _| _|", " ||_ _|", " ", " _ _ ", "|_||_ |_ ", " | _||_|", " ", " _ _ _ ", " ||_||_|", " ||_| _|", " ", ] - XCTAssertEqual(try! OcrNumber.convert(rows: input), "123,456,789") + #expect(try! OcrNumber.convert(rows: input) == "123,456,789") } } diff --git a/exercises/practice/palindrome-products/.meta/template.swift b/exercises/practice/palindrome-products/.meta/template.swift index b7d96c4e0..7038c7175 100644 --- a/exercises/practice/palindrome-products/.meta/template.swift +++ b/exercises/practice/palindrome-products/.meta/template.swift @@ -1,46 +1,48 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} + func test{{case.description |camelCase }}() { {%- if case.property == "largest" and case.expected.error -%} - XCTAssertThrowsError(try PalindromeProducts.largest(from: {{case.input.min}}, to: {{case.input.max}})) { error in - XCTAssertEqual(error as? PalindromeError, PalindromeError.invalidRange) + #expect(throws: PalindromeError.invalidRange) { + try PalindromeProducts.largest(from: {{case.input.min}}, to: {{case.input.max}}) } {%- elif case.expected.error -%} - XCTAssertThrowsError(try PalindromeProducts.smallest(from: {{case.input.min}}, to: {{case.input.max}})) { error in - XCTAssertEqual(error as? PalindromeError, PalindromeError.invalidRange) + #expect(throws: PalindromeError.invalidRange) { + try PalindromeProducts.smallest(from: {{case.input.min}}, to: {{case.input.max}}) } {%- elif case.property == "largest" -%} let largest = try! PalindromeProducts.largest(from: {{case.input.min}}, to: {{case.input.max}}) {%- ifnot case.expected.value | isNull %} - XCTAssertEqual(largest.value, {{case.expected.value}}) + #expect(largest.value == {{case.expected.value}}) {%- else %} - XCTAssertNil(largest.value) + #expect(largest.value == nil) {%- endif %} {%- if case.expected.factors.count == 0 %} - XCTAssertEqual(largest.factors, Set()) + #expect(largest.factors == Set()) {% else %} - XCTAssertEqual(largest.factors, Set(arrayLiteral: {% for value in case.expected.factors %}{% ifnot forloop.first %}, {%- endif %}{{value}}{% endfor %})) + #expect(largest.factors == Set(arrayLiteral: {% for value in case.expected.factors %}{% ifnot forloop.first %}, {%- endif %}{{value}}{% endfor %})) {%- endif %} {%- else -%} let smallest = try! PalindromeProducts.smallest(from: {{case.input.min}}, to: {{case.input.max}}) {%- ifnot case.expected.value | isNull %} - XCTAssertEqual(smallest.value, {{case.expected.value}}) + #expect(smallest.value == {{case.expected.value}}) {%- else %} - XCTAssertNil(smallest.value) + #expect(smallest.value == nil) {%- endif %} {%- if case.expected.factors.count == 0 %} - XCTAssertEqual(smallest.factors, Set()) + #expect(smallest.factors == Set()) {% else %} - XCTAssertEqual(smallest.factors, Set(arrayLiteral: {% for value in case.expected.factors %}{% ifnot forloop.first %}, {%- endif %}{{value}}{% endfor %})) + #expect(smallest.factors == Set(arrayLiteral: {% for value in case.expected.factors %}{% ifnot forloop.first %}, {%- endif %}{{value}}{% endfor %})) {%- endif %} {% endif -%} } diff --git a/exercises/practice/palindrome-products/Package.swift b/exercises/practice/palindrome-products/Package.swift index c8fb7a739..060964938 100644 --- a/exercises/practice/palindrome-products/Package.swift +++ b/exercises/practice/palindrome-products/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/palindrome-products/Tests/PalindromeProductsTests/PalindromeProductsTests.swift b/exercises/practice/palindrome-products/Tests/PalindromeProductsTests/PalindromeProductsTests.swift index 7461c8a5f..55ca914be 100644 --- a/exercises/practice/palindrome-products/Tests/PalindromeProductsTests/PalindromeProductsTests.swift +++ b/exercises/practice/palindrome-products/Tests/PalindromeProductsTests/PalindromeProductsTests.swift @@ -1,98 +1,101 @@ -import XCTest +import Foundation +import Testing @testable import PalindromeProducts -class PalindromeProductsTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PalindromeProductsTests { + + @Test("find the smallest palindrome from single digit factors") func testFindTheSmallestPalindromeFromSingleDigitFactors() { let smallest = try! PalindromeProducts.smallest(from: 1, to: 9) - XCTAssertEqual(smallest.value, 1) - XCTAssertEqual(smallest.factors, Set(arrayLiteral: [1, 1])) + #expect(smallest.value == 1) + #expect(smallest.factors == Set(arrayLiteral: [1, 1])) } - func testFindTheLargestPalindromeFromSingleDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the largest palindrome from single digit factors", .enabled(if: RUNALL)) + func testFindTheLargestPalindromeFromSingleDigitFactors() { let largest = try! PalindromeProducts.largest(from: 1, to: 9) - XCTAssertEqual(largest.value, 9) - XCTAssertEqual(largest.factors, Set(arrayLiteral: [1, 9], [3, 3])) + #expect(largest.value == 9) + #expect(largest.factors == Set(arrayLiteral: [1, 9], [3, 3])) } - func testFindTheSmallestPalindromeFromDoubleDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the smallest palindrome from double digit factors", .enabled(if: RUNALL)) + func testFindTheSmallestPalindromeFromDoubleDigitFactors() { let smallest = try! PalindromeProducts.smallest(from: 10, to: 99) - XCTAssertEqual(smallest.value, 121) - XCTAssertEqual(smallest.factors, Set(arrayLiteral: [11, 11])) + #expect(smallest.value == 121) + #expect(smallest.factors == Set(arrayLiteral: [11, 11])) } - func testFindTheLargestPalindromeFromDoubleDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the largest palindrome from double digit factors", .enabled(if: RUNALL)) + func testFindTheLargestPalindromeFromDoubleDigitFactors() { let largest = try! PalindromeProducts.largest(from: 10, to: 99) - XCTAssertEqual(largest.value, 9009) - XCTAssertEqual(largest.factors, Set(arrayLiteral: [91, 99])) + #expect(largest.value == 9009) + #expect(largest.factors == Set(arrayLiteral: [91, 99])) } - func testFindTheSmallestPalindromeFromTripleDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the smallest palindrome from triple digit factors", .enabled(if: RUNALL)) + func testFindTheSmallestPalindromeFromTripleDigitFactors() { let smallest = try! PalindromeProducts.smallest(from: 100, to: 999) - XCTAssertEqual(smallest.value, 10201) - XCTAssertEqual(smallest.factors, Set(arrayLiteral: [101, 101])) + #expect(smallest.value == 10201) + #expect(smallest.factors == Set(arrayLiteral: [101, 101])) } - func testFindTheLargestPalindromeFromTripleDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the largest palindrome from triple digit factors", .enabled(if: RUNALL)) + func testFindTheLargestPalindromeFromTripleDigitFactors() { let largest = try! PalindromeProducts.largest(from: 100, to: 999) - XCTAssertEqual(largest.value, 906609) - XCTAssertEqual(largest.factors, Set(arrayLiteral: [913, 993])) + #expect(largest.value == 906609) + #expect(largest.factors == Set(arrayLiteral: [913, 993])) } - func testFindTheSmallestPalindromeFromFourDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the smallest palindrome from four digit factors", .enabled(if: RUNALL)) + func testFindTheSmallestPalindromeFromFourDigitFactors() { let smallest = try! PalindromeProducts.smallest(from: 1000, to: 9999) - XCTAssertEqual(smallest.value, 1_002_001) - XCTAssertEqual(smallest.factors, Set(arrayLiteral: [1001, 1001])) + #expect(smallest.value == 1_002_001) + #expect(smallest.factors == Set(arrayLiteral: [1001, 1001])) } - func testFindTheLargestPalindromeFromFourDigitFactors() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("find the largest palindrome from four digit factors", .enabled(if: RUNALL)) + func testFindTheLargestPalindromeFromFourDigitFactors() { let largest = try! PalindromeProducts.largest(from: 1000, to: 9999) - XCTAssertEqual(largest.value, 99_000_099) - XCTAssertEqual(largest.factors, Set(arrayLiteral: [9901, 9999])) + #expect(largest.value == 99_000_099) + #expect(largest.factors == Set(arrayLiteral: [9901, 9999])) } - func testEmptyResultForSmallestIfNoPalindromeInTheRange() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("empty result for smallest if no palindrome in the range", .enabled(if: RUNALL)) + func testEmptyResultForSmallestIfNoPalindromeInTheRange() { let smallest = try! PalindromeProducts.smallest(from: 1002, to: 1003) - XCTAssertNil(smallest.value) - XCTAssertEqual(smallest.factors, Set()) + #expect(smallest.value == nil) + #expect(smallest.factors == Set()) } - func testEmptyResultForLargestIfNoPalindromeInTheRange() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("empty result for largest if no palindrome in the range", .enabled(if: RUNALL)) + func testEmptyResultForLargestIfNoPalindromeInTheRange() { let largest = try! PalindromeProducts.largest(from: 15, to: 15) - XCTAssertNil(largest.value) - XCTAssertEqual(largest.factors, Set()) + #expect(largest.value == nil) + #expect(largest.factors == Set()) } - func testErrorResultForSmallestIfMinIsMoreThanMax() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PalindromeProducts.smallest(from: 10000, to: 1)) { error in - XCTAssertEqual(error as? PalindromeError, PalindromeError.invalidRange) + @Test("error result for smallest if min is more than max", .enabled(if: RUNALL)) + func testErrorResultForSmallestIfMinIsMoreThanMax() { + #expect(throws: PalindromeError.invalidRange) { + try PalindromeProducts.smallest(from: 10000, to: 1) } } - func testErrorResultForLargestIfMinIsMoreThanMax() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try PalindromeProducts.largest(from: 2, to: 1)) { error in - XCTAssertEqual(error as? PalindromeError, PalindromeError.invalidRange) + @Test("error result for largest if min is more than max", .enabled(if: RUNALL)) + func testErrorResultForLargestIfMinIsMoreThanMax() { + #expect(throws: PalindromeError.invalidRange) { + try PalindromeProducts.largest(from: 2, to: 1) } } - func testSmallestProductDoesNotUseTheSmallestFactor() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("smallest product does not use the smallest factor", .enabled(if: RUNALL)) + func testSmallestProductDoesNotUseTheSmallestFactor() { let smallest = try! PalindromeProducts.smallest(from: 3215, to: 4000) - XCTAssertEqual(smallest.value, 10_988_901) - XCTAssertEqual(smallest.factors, Set(arrayLiteral: [3297, 3333])) + #expect(smallest.value == 10_988_901) + #expect(smallest.factors == Set(arrayLiteral: [3297, 3333])) } } diff --git a/exercises/practice/pangram/.meta/template.swift b/exercises/practice/pangram/.meta/template.swift index 721c0b51c..8ccbcea65 100644 --- a/exercises/practice/pangram/.meta/template.swift +++ b/exercises/practice/pangram/.meta/template.swift @@ -1,19 +1,21 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} + func test{{case.description |camelCase }}() { {%- if case.expected -%} - XCTAssertTrue(isPangram("{{case.input.sentence | inspect}}")) + #expect(isPangram("{{case.input.sentence | inspect}}")) {%- else -%} - XCTAssertFalse(isPangram("{{case.input.sentence | inspect}}")) + #expect(!isPangram("{{case.input.sentence | inspect}}")) {%- endif %} } {% endfor -%} diff --git a/exercises/practice/pangram/Package.swift b/exercises/practice/pangram/Package.swift index de35855bb..6d01d4352 100644 --- a/exercises/practice/pangram/Package.swift +++ b/exercises/practice/pangram/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/pangram/Tests/PangramTests/PangramTests.swift b/exercises/practice/pangram/Tests/PangramTests/PangramTests.swift index 5abe22889..4b9260636 100644 --- a/exercises/practice/pangram/Tests/PangramTests/PangramTests.swift +++ b/exercises/practice/pangram/Tests/PangramTests/PangramTests.swift @@ -1,56 +1,59 @@ -import XCTest +import Foundation +import Testing @testable import Pangram -class PangramTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PangramTests { + + @Test("empty sentence") func testEmptySentence() { - XCTAssertFalse(isPangram("")) + #expect(!isPangram("")) } - func testPerfectLowerCase() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(isPangram("abcdefghijklmnopqrstuvwxyz")) + @Test("perfect lower case", .enabled(if: RUNALL)) + func testPerfectLowerCase() { + #expect(isPangram("abcdefghijklmnopqrstuvwxyz")) } - func testOnlyLowerCase() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(isPangram("the quick brown fox jumps over the lazy dog")) + @Test("only lower case", .enabled(if: RUNALL)) + func testOnlyLowerCase() { + #expect(isPangram("the quick brown fox jumps over the lazy dog")) } - func testMissingTheLetterX() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(isPangram("a quick movement of the enemy will jeopardize five gunboats")) + @Test("missing the letter 'x'", .enabled(if: RUNALL)) + func testMissingTheLetterX() { + #expect(!isPangram("a quick movement of the enemy will jeopardize five gunboats")) } - func testMissingTheLetterH() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(isPangram("five boxing wizards jump quickly at it")) + @Test("missing the letter 'h'", .enabled(if: RUNALL)) + func testMissingTheLetterH() { + #expect(!isPangram("five boxing wizards jump quickly at it")) } - func testWithUnderscores() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog")) + @Test("with underscores", .enabled(if: RUNALL)) + func testWithUnderscores() { + #expect(isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog")) } - func testWithNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(isPangram("the 1 quick brown fox jumps over the 2 lazy dogs")) + @Test("with numbers", .enabled(if: RUNALL)) + func testWithNumbers() { + #expect(isPangram("the 1 quick brown fox jumps over the 2 lazy dogs")) } - func testMissingLettersReplacedByNumbers() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")) + @Test("missing letters replaced by numbers", .enabled(if: RUNALL)) + func testMissingLettersReplacedByNumbers() { + #expect(!isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")) } - func testMixedCaseAndPunctuation() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertTrue(isPangram("\"Five quacking Zephyrs jolt my wax bed.\"")) + @Test("mixed case and punctuation", .enabled(if: RUNALL)) + func testMixedCaseAndPunctuation() { + #expect(isPangram("\"Five quacking Zephyrs jolt my wax bed.\"")) } - func testAMAndAMAre26DifferentCharactersButNotAPangram() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertFalse(isPangram("abcdefghijklm ABCDEFGHIJKLM")) + @Test("a-m and A-M are 26 different characters but not a pangram", .enabled(if: RUNALL)) + func testAMAndAMAre26DifferentCharactersButNotAPangram() { + #expect(!isPangram("abcdefghijklm ABCDEFGHIJKLM")) } }