Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift 6]: Update Exercises batch 13 #797

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions exercises/practice/prime-factors/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -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 -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/prime-factors/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -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])
}
}
8 changes: 4 additions & 4 deletions exercises/practice/protein-translation/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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 |
Expand Down
20 changes: 11 additions & 9 deletions exercises/practice/protein-translation/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -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 -%}
}
Expand Down
4 changes: 4 additions & 0 deletions exercises/practice/protein-translation/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/protein-translation/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0

import PackageDescription

Expand Down
Loading
Loading