diff --git a/exercises/practice/prime-factors/.meta/template.swift b/exercises/practice/prime-factors/.meta/template.swift index 70bb0ec07..546dd13c2 100644 --- a/exercises/practice/prime-factors/.meta/template.swift +++ b/exercises/practice/prime-factors/.meta/template.swift @@ -1,16 +1,18 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} - XCTAssertEqual(primeFactors({{case.input.value}}), {{case.expected}}) + func test{{case.description |camelCase }}() { + #expect(primeFactors({{case.input.value}}) == {{case.expected}}) } {% endfor -%} } diff --git a/exercises/practice/prime-factors/Package.swift b/exercises/practice/prime-factors/Package.swift index 1344ebb78..393e30fa8 100644 --- a/exercises/practice/prime-factors/Package.swift +++ b/exercises/practice/prime-factors/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/prime-factors/Tests/PrimeFactorsTests/PrimeFactorsTests.swift b/exercises/practice/prime-factors/Tests/PrimeFactorsTests/PrimeFactorsTests.swift index ac7c791d8..47063399e 100644 --- a/exercises/practice/prime-factors/Tests/PrimeFactorsTests/PrimeFactorsTests.swift +++ b/exercises/practice/prime-factors/Tests/PrimeFactorsTests/PrimeFactorsTests.swift @@ -1,66 +1,69 @@ -import XCTest +import Foundation +import Testing @testable import PrimeFactors -class PrimeFactorsTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PrimeFactorsTests { + + @Test("no factors") func testNoFactors() { - XCTAssertEqual(primeFactors(1), []) + #expect(primeFactors(1) == []) } - func testPrimeNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(2), [2]) + @Test("prime number", .enabled(if: RUNALL)) + func testPrimeNumber() { + #expect(primeFactors(2) == [2]) } - func testAnotherPrimeNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(3), [3]) + @Test("another prime number", .enabled(if: RUNALL)) + func testAnotherPrimeNumber() { + #expect(primeFactors(3) == [3]) } - func testSquareOfAPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(9), [3, 3]) + @Test("square of a prime", .enabled(if: RUNALL)) + func testSquareOfAPrime() { + #expect(primeFactors(9) == [3, 3]) } - func testProductOfFirstPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(4), [2, 2]) + @Test("product of first prime", .enabled(if: RUNALL)) + func testProductOfFirstPrime() { + #expect(primeFactors(4) == [2, 2]) } - func testCubeOfAPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(8), [2, 2, 2]) + @Test("cube of a prime", .enabled(if: RUNALL)) + func testCubeOfAPrime() { + #expect(primeFactors(8) == [2, 2, 2]) } - func testProductOfSecondPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(27), [3, 3, 3]) + @Test("product of second prime", .enabled(if: RUNALL)) + func testProductOfSecondPrime() { + #expect(primeFactors(27) == [3, 3, 3]) } - func testProductOfThirdPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(625), [5, 5, 5, 5]) + @Test("product of third prime", .enabled(if: RUNALL)) + func testProductOfThirdPrime() { + #expect(primeFactors(625) == [5, 5, 5, 5]) } - func testProductOfFirstAndSecondPrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(6), [2, 3]) + @Test("product of first and second prime", .enabled(if: RUNALL)) + func testProductOfFirstAndSecondPrime() { + #expect(primeFactors(6) == [2, 3]) } - func testProductOfPrimesAndNonPrimes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(12), [2, 2, 3]) + @Test("product of primes and non-primes", .enabled(if: RUNALL)) + func testProductOfPrimesAndNonPrimes() { + #expect(primeFactors(12) == [2, 2, 3]) } - func testProductOfPrimes() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(901255), [5, 17, 23, 461]) + @Test("product of primes", .enabled(if: RUNALL)) + func testProductOfPrimes() { + #expect(primeFactors(901255) == [5, 17, 23, 461]) } - func testFactorsIncludeALargePrime() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(primeFactors(93_819_012_551), [11, 9539, 894119]) + @Test("factors include a large prime", .enabled(if: RUNALL)) + func testFactorsIncludeALargePrime() { + #expect(primeFactors(93_819_012_551) == [11, 9539, 894119]) } } diff --git a/exercises/practice/protein-translation/.docs/instructions.md b/exercises/practice/protein-translation/.docs/instructions.md index 7dc34d2ed..44880802c 100644 --- a/exercises/practice/protein-translation/.docs/instructions.md +++ b/exercises/practice/protein-translation/.docs/instructions.md @@ -2,12 +2,12 @@ Translate RNA sequences into proteins. -RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so: +RNA can be broken into three-nucleotide sequences called codons, and then translated to a protein like so: RNA: `"AUGUUUUCU"` => translates to Codons: `"AUG", "UUU", "UCU"` -=> which become a polypeptide with the following sequence => +=> which become a protein with the following sequence => Protein: `"Methionine", "Phenylalanine", "Serine"` @@ -27,9 +27,9 @@ Protein: `"Methionine", "Phenylalanine", "Serine"` Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence. -Below are the codons and resulting Amino Acids needed for the exercise. +Below are the codons and resulting amino acids needed for the exercise. -| Codon | Protein | +| Codon | Amino Acid | | :----------------- | :------------ | | AUG | Methionine | | UUU, UUC | Phenylalanine | diff --git a/exercises/practice/protein-translation/.meta/template.swift b/exercises/practice/protein-translation/.meta/template.swift index 0fe923ba5..05997d9dc 100644 --- a/exercises/practice/protein-translation/.meta/template.swift +++ b/exercises/practice/protein-translation/.meta/template.swift @@ -1,20 +1,22 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} + func test{{case.description |camelCase }}() { {%- ifnot case.expected.error -%} - XCTAssertEqual({{case.expected | toStringArray}}, try! translationOfRNA(rna: "{{case.input.strand}}")) + #expect(try! translationOfRNA(rna: "{{case.input.strand}}") == {{case.expected | toStringArray}}) {%- else -%} - XCTAssertThrowsError(try translationOfRNA(rna: "{{case.input.strand}}")) { error in - XCTAssertEqual(error as? TranslationError, TranslationError.invalidCodon) + #expect(throws: TranslationError.invalidCodon) { + try translationOfRNA(rna: "{{case.input.strand}}") } {%- endif -%} } diff --git a/exercises/practice/protein-translation/.meta/tests.toml b/exercises/practice/protein-translation/.meta/tests.toml index 5fb189070..b465aed23 100644 --- a/exercises/practice/protein-translation/.meta/tests.toml +++ b/exercises/practice/protein-translation/.meta/tests.toml @@ -87,11 +87,15 @@ description = "Translation stops if STOP codon in middle of three-codon sequence [2c2a2a60-401f-4a80-b977-e0715b23b93d] description = "Translation stops if STOP codon in middle of six-codon sequence" +[f6f92714-769f-4187-9524-e353e8a41a80] +description = "Sequence of two non-STOP codons does not translate to a STOP codon" + [1e75ea2a-f907-4994-ae5c-118632a1cb0f] description = "Non-existing codon can't translate" [9eac93f3-627a-4c90-8653-6d0a0595bc6f] description = "Unknown amino acids, not part of a codon, can't translate" +reimplements = "1e75ea2a-f907-4994-ae5c-118632a1cb0f" [9d73899f-e68e-4291-b1e2-7bf87c00f024] description = "Incomplete RNA sequence can't translate" diff --git a/exercises/practice/protein-translation/Package.swift b/exercises/practice/protein-translation/Package.swift index b214de98d..4ec57e57d 100644 --- a/exercises/practice/protein-translation/Package.swift +++ b/exercises/practice/protein-translation/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/protein-translation/Tests/ProteinTranslationTests/ProteinTranslationTests.swift b/exercises/practice/protein-translation/Tests/ProteinTranslationTests/ProteinTranslationTests.swift index 6c7245f6e..b241d5071 100644 --- a/exercises/practice/protein-translation/Tests/ProteinTranslationTests/ProteinTranslationTests.swift +++ b/exercises/practice/protein-translation/Tests/ProteinTranslationTests/ProteinTranslationTests.swift @@ -1,164 +1,140 @@ -import XCTest +import Foundation +import Testing @testable import ProteinTranslation -class ProteinTranslationTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false - func testEmptyRnaSequenceResultsInNoProteins() { - XCTAssertEqual([], try! translationOfRNA(rna: "")) - } +@Suite struct ProteinTranslationTests { - func testMethionineRnaSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Methionine"], try! translationOfRNA(rna: "AUG")) - } + @Test("Empty RNA sequence results in no proteins") + func testEmptyRnaSequenceResultsInNoProteins() { #expect(try! translationOfRNA(rna: "") == []) } - func testPhenylalanineRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Phenylalanine"], try! translationOfRNA(rna: "UUU")) - } + @Test("Methionine RNA sequence", .enabled(if: RUNALL)) + func testMethionineRnaSequence() { #expect(try! translationOfRNA(rna: "AUG") == ["Methionine"]) } - func testPhenylalanineRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Phenylalanine"], try! translationOfRNA(rna: "UUC")) + @Test("Phenylalanine RNA sequence 1", .enabled(if: RUNALL)) + func testPhenylalanineRnaSequence1() { + #expect(try! translationOfRNA(rna: "UUU") == ["Phenylalanine"]) } - func testLeucineRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Leucine"], try! translationOfRNA(rna: "UUA")) + @Test("Phenylalanine RNA sequence 2", .enabled(if: RUNALL)) + func testPhenylalanineRnaSequence2() { + #expect(try! translationOfRNA(rna: "UUC") == ["Phenylalanine"]) } - func testLeucineRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Leucine"], try! translationOfRNA(rna: "UUG")) - } + @Test("Leucine RNA sequence 1", .enabled(if: RUNALL)) + func testLeucineRnaSequence1() { #expect(try! translationOfRNA(rna: "UUA") == ["Leucine"]) } - func testSerineRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Serine"], try! translationOfRNA(rna: "UCU")) - } + @Test("Leucine RNA sequence 2", .enabled(if: RUNALL)) + func testLeucineRnaSequence2() { #expect(try! translationOfRNA(rna: "UUG") == ["Leucine"]) } - func testSerineRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Serine"], try! translationOfRNA(rna: "UCC")) - } + @Test("Serine RNA sequence 1", .enabled(if: RUNALL)) + func testSerineRnaSequence1() { #expect(try! translationOfRNA(rna: "UCU") == ["Serine"]) } - func testSerineRnaSequence3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Serine"], try! translationOfRNA(rna: "UCA")) - } + @Test("Serine RNA sequence 2", .enabled(if: RUNALL)) + func testSerineRnaSequence2() { #expect(try! translationOfRNA(rna: "UCC") == ["Serine"]) } - func testSerineRnaSequence4() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Serine"], try! translationOfRNA(rna: "UCG")) - } + @Test("Serine RNA sequence 3", .enabled(if: RUNALL)) + func testSerineRnaSequence3() { #expect(try! translationOfRNA(rna: "UCA") == ["Serine"]) } - func testTyrosineRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Tyrosine"], try! translationOfRNA(rna: "UAU")) - } + @Test("Serine RNA sequence 4", .enabled(if: RUNALL)) + func testSerineRnaSequence4() { #expect(try! translationOfRNA(rna: "UCG") == ["Serine"]) } - func testTyrosineRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Tyrosine"], try! translationOfRNA(rna: "UAC")) - } + @Test("Tyrosine RNA sequence 1", .enabled(if: RUNALL)) + func testTyrosineRnaSequence1() { #expect(try! translationOfRNA(rna: "UAU") == ["Tyrosine"]) } - func testCysteineRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Cysteine"], try! translationOfRNA(rna: "UGU")) - } + @Test("Tyrosine RNA sequence 2", .enabled(if: RUNALL)) + func testTyrosineRnaSequence2() { #expect(try! translationOfRNA(rna: "UAC") == ["Tyrosine"]) } - func testCysteineRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Cysteine"], try! translationOfRNA(rna: "UGC")) - } + @Test("Cysteine RNA sequence 1", .enabled(if: RUNALL)) + func testCysteineRnaSequence1() { #expect(try! translationOfRNA(rna: "UGU") == ["Cysteine"]) } - func testTryptophanRnaSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Tryptophan"], try! translationOfRNA(rna: "UGG")) - } + @Test("Cysteine RNA sequence 2", .enabled(if: RUNALL)) + func testCysteineRnaSequence2() { #expect(try! translationOfRNA(rna: "UGC") == ["Cysteine"]) } - func testStopCodonRnaSequence1() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual([], try! translationOfRNA(rna: "UAA")) - } + @Test("Tryptophan RNA sequence", .enabled(if: RUNALL)) + func testTryptophanRnaSequence() { #expect(try! translationOfRNA(rna: "UGG") == ["Tryptophan"]) } - func testStopCodonRnaSequence2() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual([], try! translationOfRNA(rna: "UAG")) - } + @Test("STOP codon RNA sequence 1", .enabled(if: RUNALL)) + func testStopCodonRnaSequence1() { #expect(try! translationOfRNA(rna: "UAA") == []) } + + @Test("STOP codon RNA sequence 2", .enabled(if: RUNALL)) + func testStopCodonRnaSequence2() { #expect(try! translationOfRNA(rna: "UAG") == []) } + + @Test("STOP codon RNA sequence 3", .enabled(if: RUNALL)) + func testStopCodonRnaSequence3() { #expect(try! translationOfRNA(rna: "UGA") == []) } - func testStopCodonRnaSequence3() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual([], try! translationOfRNA(rna: "UGA")) + @Test("Sequence of two protein codons translates into proteins", .enabled(if: RUNALL)) + func testSequenceOfTwoProteinCodonsTranslatesIntoProteins() { + #expect(try! translationOfRNA(rna: "UUUUUU") == ["Phenylalanine", "Phenylalanine"]) } - func testSequenceOfTwoProteinCodonsTranslatesIntoProteins() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Phenylalanine", "Phenylalanine"], try! translationOfRNA(rna: "UUUUUU")) + @Test("Sequence of two different protein codons translates into proteins", .enabled(if: RUNALL)) + func testSequenceOfTwoDifferentProteinCodonsTranslatesIntoProteins() { + #expect(try! translationOfRNA(rna: "UUAUUG") == ["Leucine", "Leucine"]) } - func testSequenceOfTwoDifferentProteinCodonsTranslatesIntoProteins() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Leucine", "Leucine"], try! translationOfRNA(rna: "UUAUUG")) + @Test("Translate RNA strand into correct protein list", .enabled(if: RUNALL)) + func testTranslateRnaStrandIntoCorrectProteinList() { + #expect( + try! translationOfRNA(rna: "AUGUUUUGG") == ["Methionine", "Phenylalanine", "Tryptophan"]) } - func testTranslateRnaStrandIntoCorrectProteinList() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - ["Methionine", "Phenylalanine", "Tryptophan"], try! translationOfRNA(rna: "AUGUUUUGG")) + @Test("Translation stops if STOP codon at beginning of sequence", .enabled(if: RUNALL)) + func testTranslationStopsIfStopCodonAtBeginningOfSequence() { + #expect(try! translationOfRNA(rna: "UAGUGG") == []) } - func testTranslationStopsIfStopCodonAtBeginningOfSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual([], try! translationOfRNA(rna: "UAGUGG")) + @Test("Translation stops if STOP codon at end of two-codon sequence", .enabled(if: RUNALL)) + func testTranslationStopsIfStopCodonAtEndOfTwoCodonSequence() { + #expect(try! translationOfRNA(rna: "UGGUAG") == ["Tryptophan"]) } - func testTranslationStopsIfStopCodonAtEndOfTwoCodonSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Tryptophan"], try! translationOfRNA(rna: "UGGUAG")) + @Test("Translation stops if STOP codon at end of three-codon sequence", .enabled(if: RUNALL)) + func testTranslationStopsIfStopCodonAtEndOfThreeCodonSequence() { + #expect(try! translationOfRNA(rna: "AUGUUUUAA") == ["Methionine", "Phenylalanine"]) } - func testTranslationStopsIfStopCodonAtEndOfThreeCodonSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Methionine", "Phenylalanine"], try! translationOfRNA(rna: "AUGUUUUAA")) + @Test("Translation stops if STOP codon in middle of three-codon sequence", .enabled(if: RUNALL)) + func testTranslationStopsIfStopCodonInMiddleOfThreeCodonSequence() { + #expect(try! translationOfRNA(rna: "UGGUAGUGG") == ["Tryptophan"]) } - func testTranslationStopsIfStopCodonInMiddleOfThreeCodonSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Tryptophan"], try! translationOfRNA(rna: "UGGUAGUGG")) + @Test("Translation stops if STOP codon in middle of six-codon sequence", .enabled(if: RUNALL)) + func testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence() { + #expect( + try! translationOfRNA(rna: "UGGUGUUAUUAAUGGUUU") == ["Tryptophan", "Cysteine", "Tyrosine"]) } - func testTranslationStopsIfStopCodonInMiddleOfSixCodonSequence() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - ["Tryptophan", "Cysteine", "Tyrosine"], try! translationOfRNA(rna: "UGGUGUUAUUAAUGGUUU")) + @Test("Sequence of two non-STOP codons does not translate to a STOP codon", .enabled(if: RUNALL)) + func testSequenceOfTwoNonStopCodonsDoesNotTranslateToAStopCodon() { + #expect(try! translationOfRNA(rna: "AUGAUG") == ["Methionine", "Methionine"]) } - func testNonExistingCodonCantTranslate() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try translationOfRNA(rna: "AAA")) { error in - XCTAssertEqual(error as? TranslationError, TranslationError.invalidCodon) + @Test("Non-existing codon can't translate", .enabled(if: RUNALL)) + func testNonExistingCodonCantTranslate() { + #expect(throws: TranslationError.invalidCodon) { + try translationOfRNA(rna: "AAA") } } - func testUnknownAminoAcidsNotPartOfACodonCantTranslate() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try translationOfRNA(rna: "XYZ")) { error in - XCTAssertEqual(error as? TranslationError, TranslationError.invalidCodon) + @Test("Unknown amino acids, not part of a codon, can't translate", .enabled(if: RUNALL)) + func testUnknownAminoAcidsNotPartOfACodonCantTranslate() { + #expect(throws: TranslationError.invalidCodon) { + try translationOfRNA(rna: "XYZ") } } - func testIncompleteRnaSequenceCantTranslate() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertThrowsError(try translationOfRNA(rna: "AUGU")) { error in - XCTAssertEqual(error as? TranslationError, TranslationError.invalidCodon) + @Test("Incomplete RNA sequence can't translate", .enabled(if: RUNALL)) + func testIncompleteRnaSequenceCantTranslate() { + #expect(throws: TranslationError.invalidCodon) { + try translationOfRNA(rna: "AUGU") } } - func testIncompleteRnaSequenceCanTranslateIfValidUntilAStopCodon() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(["Phenylalanine", "Phenylalanine"], try! translationOfRNA(rna: "UUCUUCUAAUGGU")) + @Test("Incomplete RNA sequence can translate if valid until a STOP codon", .enabled(if: RUNALL)) + func testIncompleteRnaSequenceCanTranslateIfValidUntilAStopCodon() { + #expect(try! translationOfRNA(rna: "UUCUUCUAAUGGU") == ["Phenylalanine", "Phenylalanine"]) } } diff --git a/exercises/practice/proverb/.meta/template.swift b/exercises/practice/proverb/.meta/template.swift index 2573d6d15..2a2656717 100644 --- a/exercises/practice/proverb/.meta/template.swift +++ b/exercises/practice/proverb/.meta/template.swift @@ -1,17 +1,19 @@ -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 expected = "{{case.expected | join: "\n" + "" }}" - XCTAssertEqual(Proverb({{case.input.strings | toStringArray}}).recite(), expected) + #expect(Proverb({{case.input.strings | toStringArray}}).recite() == expected) } {% endfor -%} } diff --git a/exercises/practice/proverb/Package.swift b/exercises/practice/proverb/Package.swift index c5e4d86e9..9eb68c8bb 100644 --- a/exercises/practice/proverb/Package.swift +++ b/exercises/practice/proverb/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/proverb/Tests/ProverbTests/ProverbTests.swift b/exercises/practice/proverb/Tests/ProverbTests/ProverbTests.swift index 3a456e91b..e171be0c8 100644 --- a/exercises/practice/proverb/Tests/ProverbTests/ProverbTests.swift +++ b/exercises/practice/proverb/Tests/ProverbTests/ProverbTests.swift @@ -1,52 +1,55 @@ -import XCTest +import Foundation +import Testing @testable import Proverb -class ProverbTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct ProverbTests { + + @Test("zero pieces") func testZeroPieces() { let expected = "" - XCTAssertEqual(Proverb([]).recite(), expected) + #expect(Proverb([]).recite() == expected) } - func testOnePiece() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("one piece", .enabled(if: RUNALL)) + func testOnePiece() { let expected = "And all for the want of a nail." - XCTAssertEqual(Proverb(["nail"]).recite(), expected) + #expect(Proverb(["nail"]).recite() == expected) } - func testTwoPieces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("two pieces", .enabled(if: RUNALL)) + func testTwoPieces() { let expected = "For want of a nail the shoe was lost.\n" + "And all for the want of a nail." - XCTAssertEqual(Proverb(["nail", "shoe"]).recite(), expected) + #expect(Proverb(["nail", "shoe"]).recite() == expected) } - func testThreePieces() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("three pieces", .enabled(if: RUNALL)) + func testThreePieces() { let expected = "For want of a nail the shoe was lost.\n" + "For want of a shoe the horse was lost.\n" + "And all for the want of a nail." - XCTAssertEqual(Proverb(["nail", "shoe", "horse"]).recite(), expected) + #expect(Proverb(["nail", "shoe", "horse"]).recite() == expected) } - func testFullProverb() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("full proverb", .enabled(if: RUNALL)) + func testFullProverb() { let expected = "For want of a nail the shoe was lost.\n" + "For want of a shoe the horse was lost.\n" + "For want of a horse the rider was lost.\n" + "For want of a rider the message was lost.\n" + "For want of a message the battle was lost.\n" + "For want of a battle the kingdom was lost.\n" + "And all for the want of a nail." - XCTAssertEqual( - Proverb(["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]).recite(), expected - ) + #expect( + Proverb(["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]).recite() + == expected) } - func testFourPiecesModernized() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("four pieces modernized", .enabled(if: RUNALL)) + func testFourPiecesModernized() { let expected = "For want of a pin the gun was lost.\n" + "For want of a gun the soldier was lost.\n" + "For want of a soldier the battle was lost.\n" + "And all for the want of a pin." - XCTAssertEqual(Proverb(["pin", "gun", "soldier", "battle"]).recite(), expected) + #expect(Proverb(["pin", "gun", "soldier", "battle"]).recite() == expected) } } diff --git a/exercises/practice/pythagorean-triplet/.docs/instructions.md b/exercises/practice/pythagorean-triplet/.docs/instructions.md index 1c1a8aea6..ced833d7a 100644 --- a/exercises/practice/pythagorean-triplet/.docs/instructions.md +++ b/exercises/practice/pythagorean-triplet/.docs/instructions.md @@ -1,4 +1,4 @@ -# Instructions +# Description A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which, diff --git a/exercises/practice/pythagorean-triplet/.docs/introduction.md b/exercises/practice/pythagorean-triplet/.docs/introduction.md new file mode 100644 index 000000000..3453c6ed4 --- /dev/null +++ b/exercises/practice/pythagorean-triplet/.docs/introduction.md @@ -0,0 +1,19 @@ +# Introduction + +You are an accomplished problem-solver, known for your ability to tackle the most challenging mathematical puzzles. +One evening, you receive an urgent letter from an inventor called the Triangle Tinkerer, who is working on a groundbreaking new project. +The letter reads: + +> Dear Mathematician, +> +> I need your help. +> I am designing a device that relies on the unique properties of Pythagorean triplets — sets of three integers that satisfy the equation a² + b² = c². +> This device will revolutionize navigation, but for it to work, I must program it with every possible triplet where the sum of a, b, and c equals a specific number, N. +> Calculating these triplets by hand would take me years, but I hear you are more than up to the task. +> +> Time is of the essence. +> The future of my invention — and perhaps even the future of mathematical innovation — rests on your ability to solve this problem. + +Motivated by the importance of the task, you set out to find all Pythagorean triplets that satisfy the condition. +Your work could have far-reaching implications, unlocking new possibilities in science and engineering. +Can you rise to the challenge and make history? diff --git a/exercises/practice/pythagorean-triplet/.meta/config.json b/exercises/practice/pythagorean-triplet/.meta/config.json index 12e5ec945..6d32c5033 100644 --- a/exercises/practice/pythagorean-triplet/.meta/config.json +++ b/exercises/practice/pythagorean-triplet/.meta/config.json @@ -24,7 +24,7 @@ ".meta/Sources/PythagoreanTriplet/PythagoreanTripletExample.swift" ] }, - "blurb": "There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the triplet.", - "source": "Problem 9 at Project Euler", + "blurb": "Given an integer N, find all Pythagorean triplets for which a + b + c = N.", + "source": "A variation of Problem 9 from Project Euler", "source_url": "https://projecteuler.net/problem=9" } diff --git a/exercises/practice/pythagorean-triplet/.meta/template.swift b/exercises/practice/pythagorean-triplet/.meta/template.swift index e742e0db3..00b347b3e 100644 --- a/exercises/practice/pythagorean-triplet/.meta/template.swift +++ b/exercises/practice/pythagorean-triplet/.meta/template.swift @@ -1,16 +1,18 @@ -import XCTest +import Testing +import Foundation @testable import {{exercise|camelCase}} -class {{exercise|camelCase}}Tests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false + +@Suite struct {{exercise|camelCase}}Tests { {% for case in cases %} {% if forloop.first -%} - func test{{case.description |camelCase }}() { + @Test("{{case.description}}") {% else -%} - func test{{case.description |camelCase }}() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test + @Test("{{case.description}}", .enabled(if: RUNALL)) {% endif -%} - XCTAssertEqual(tripletsWithSum({{case.input.n}}), {{case.expected}}) + func test{{case.description |camelCase }}() { + #expect(tripletsWithSum({{case.input.n}}) == {{case.expected}}) } {% endfor -%} } diff --git a/exercises/practice/pythagorean-triplet/Package.swift b/exercises/practice/pythagorean-triplet/Package.swift index 6fb6eec57..27a71c6f9 100644 --- a/exercises/practice/pythagorean-triplet/Package.swift +++ b/exercises/practice/pythagorean-triplet/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription diff --git a/exercises/practice/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift b/exercises/practice/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift index 51dc8059a..45a142b4b 100644 --- a/exercises/practice/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift +++ b/exercises/practice/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift @@ -1,49 +1,50 @@ -import XCTest +import Foundation +import Testing @testable import PythagoreanTriplet -class PythagoreanTripletTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +@Suite struct PythagoreanTripletTests { + + @Test("triplets whose sum is 12") func testTripletsWhoseSumIs12() { - XCTAssertEqual(tripletsWithSum(12), [[3, 4, 5]]) + #expect(tripletsWithSum(12) == [[3, 4, 5]]) } - func testTripletsWhoseSumIs108() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(tripletsWithSum(108), [[27, 36, 45]]) + @Test("triplets whose sum is 108", .enabled(if: RUNALL)) + func testTripletsWhoseSumIs108() { + #expect(tripletsWithSum(108) == [[27, 36, 45]]) } - func testTripletsWhoseSumIs1000() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(tripletsWithSum(1000), [[200, 375, 425]]) + @Test("triplets whose sum is 1000", .enabled(if: RUNALL)) + func testTripletsWhoseSumIs1000() { + #expect(tripletsWithSum(1000) == [[200, 375, 425]]) } - func testNoMatchingTripletsFor1001() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(tripletsWithSum(1001), []) + @Test("no matching triplets for 1001", .enabled(if: RUNALL)) + func testNoMatchingTripletsFor1001() { + #expect(tripletsWithSum(1001) == []) } - func testReturnsAllMatchingTriplets() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual(tripletsWithSum(90), [[9, 40, 41], [15, 36, 39]]) + @Test("returns all matching triplets", .enabled(if: RUNALL)) + func testReturnsAllMatchingTriplets() { + #expect(tripletsWithSum(90) == [[9, 40, 41], [15, 36, 39]]) } - func testSeveralMatchingTriplets() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - tripletsWithSum(840), - [ + @Test("several matching triplets", .enabled(if: RUNALL)) + func testSeveralMatchingTriplets() { + #expect( + tripletsWithSum(840) == [ [40, 399, 401], [56, 390, 394], [105, 360, 375], [120, 350, 370], [140, 336, 364], [168, 315, 357], [210, 280, 350], [240, 252, 348], ]) } - func testTripletsForLargeNumber() throws { - try XCTSkipIf(true && !runAll) // change true to false to run this test - XCTAssertEqual( - tripletsWithSum(30000), - [ + @Test("triplets for large number", .enabled(if: RUNALL)) + func testTripletsForLargeNumber() { + #expect( + tripletsWithSum(30000) == [ [1200, 14375, 14425], [1875, 14000, 14125], [5000, 12000, 13000], [6000, 11250, 12750], [7500, 10000, 12500], ])