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 14 #798

Draft
wants to merge 3 commits 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/raindrops/.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(raindrops({{case.input.number}}), "{{case.expected}}")
func test{{case.description |camelCase }}() {
#expect(raindrops({{case.input.number}}) == "{{case.expected}}")
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/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
115 changes: 60 additions & 55 deletions exercises/practice/raindrops/Tests/RaindropsTests/RaindropsTests.swift
Original file line number Diff line number Diff line change
@@ -1,96 +1,101 @@
import XCTest
import Foundation
import Testing

@testable import Raindrops

class RaindropsTests: XCTestCase {
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

@Suite struct RaindropsTests {

@Test("the sound for 1 is 1")
func testTheSoundFor1Is1() {
XCTAssertEqual(raindrops(1), "1")
#expect(raindrops(1) == "1")
}

func testTheSoundFor3IsPling() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(3), "Pling")
@Test("the sound for 3 is Pling", .enabled(if: RUNALL))
func testTheSoundFor3IsPling() {
#expect(raindrops(3) == "Pling")
}

func testTheSoundFor5IsPlang() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(5), "Plang")
@Test("the sound for 5 is Plang", .enabled(if: RUNALL))
func testTheSoundFor5IsPlang() {
#expect(raindrops(5) == "Plang")
}

func testTheSoundFor7IsPlong() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(7), "Plong")
@Test("the sound for 7 is Plong", .enabled(if: RUNALL))
func testTheSoundFor7IsPlong() {
#expect(raindrops(7) == "Plong")
}

func testTheSoundFor6IsPlingAsItHasAFactor3() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(6), "Pling")
@Test("the sound for 6 is Pling as it has a factor 3", .enabled(if: RUNALL))
func testTheSoundFor6IsPlingAsItHasAFactor3() {
#expect(raindrops(6) == "Pling")
}

func test2ToThePower3DoesNotMakeARaindropSoundAs3IsTheExponentNotTheBase() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(8), "8")
@Test(
"2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base",
.enabled(if: RUNALL))
func test2ToThePower3DoesNotMakeARaindropSoundAs3IsTheExponentNotTheBase() {
#expect(raindrops(8) == "8")
}

func testTheSoundFor9IsPlingAsItHasAFactor3() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(9), "Pling")
@Test("the sound for 9 is Pling as it has a factor 3", .enabled(if: RUNALL))
func testTheSoundFor9IsPlingAsItHasAFactor3() {
#expect(raindrops(9) == "Pling")
}

func testTheSoundFor10IsPlangAsItHasAFactor5() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(10), "Plang")
@Test("the sound for 10 is Plang as it has a factor 5", .enabled(if: RUNALL))
func testTheSoundFor10IsPlangAsItHasAFactor5() {
#expect(raindrops(10) == "Plang")
}

func testTheSoundFor14IsPlongAsItHasAFactorOf7() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(14), "Plong")
@Test("the sound for 14 is Plong as it has a factor of 7", .enabled(if: RUNALL))
func testTheSoundFor14IsPlongAsItHasAFactorOf7() {
#expect(raindrops(14) == "Plong")
}

func testTheSoundFor15IsPlingplangAsItHasFactors3And5() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(15), "PlingPlang")
@Test("the sound for 15 is PlingPlang as it has factors 3 and 5", .enabled(if: RUNALL))
func testTheSoundFor15IsPlingplangAsItHasFactors3And5() {
#expect(raindrops(15) == "PlingPlang")
}

func testTheSoundFor21IsPlingplongAsItHasFactors3And7() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(21), "PlingPlong")
@Test("the sound for 21 is PlingPlong as it has factors 3 and 7", .enabled(if: RUNALL))
func testTheSoundFor21IsPlingplongAsItHasFactors3And7() {
#expect(raindrops(21) == "PlingPlong")
}

func testTheSoundFor25IsPlangAsItHasAFactor5() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(25), "Plang")
@Test("the sound for 25 is Plang as it has a factor 5", .enabled(if: RUNALL))
func testTheSoundFor25IsPlangAsItHasAFactor5() {
#expect(raindrops(25) == "Plang")
}

func testTheSoundFor27IsPlingAsItHasAFactor3() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(27), "Pling")
@Test("the sound for 27 is Pling as it has a factor 3", .enabled(if: RUNALL))
func testTheSoundFor27IsPlingAsItHasAFactor3() {
#expect(raindrops(27) == "Pling")
}

func testTheSoundFor35IsPlangplongAsItHasFactors5And7() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(35), "PlangPlong")
@Test("the sound for 35 is PlangPlong as it has factors 5 and 7", .enabled(if: RUNALL))
func testTheSoundFor35IsPlangplongAsItHasFactors5And7() {
#expect(raindrops(35) == "PlangPlong")
}

func testTheSoundFor49IsPlongAsItHasAFactor7() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(49), "Plong")
@Test("the sound for 49 is Plong as it has a factor 7", .enabled(if: RUNALL))
func testTheSoundFor49IsPlongAsItHasAFactor7() {
#expect(raindrops(49) == "Plong")
}

func testTheSoundFor52Is52() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(52), "52")
@Test("the sound for 52 is 52", .enabled(if: RUNALL))
func testTheSoundFor52Is52() {
#expect(raindrops(52) == "52")
}

func testTheSoundFor105IsPlingplangplongAsItHasFactors35And7() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(105), "PlingPlangPlong")
@Test("the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7", .enabled(if: RUNALL))
func testTheSoundFor105IsPlingplangplongAsItHasFactors35And7() {
#expect(raindrops(105) == "PlingPlangPlong")
}

func testTheSoundFor3125IsPlangAsItHasAFactor5() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(raindrops(3125), "Plang")
@Test("the sound for 3125 is Plang as it has a factor 5", .enabled(if: RUNALL))
func testTheSoundFor3125IsPlangAsItHasAFactor5() {
#expect(raindrops(3125) == "Plang")
}
}
16 changes: 9 additions & 7 deletions exercises/practice/reverse-string/.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(reverseString("{{case.input.value}}"), "{{case.expected}}")
func test{{case.description |camelCase }}() {
#expect(reverseString("{{case.input.value}}") == "{{case.expected}}")
}
{% endfor -%}
}
12 changes: 12 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"
include = false

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"
include = false

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
include = false
2 changes: 1 addition & 1 deletion exercises/practice/reverse-string/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,36 +1,39 @@
import XCTest
import Foundation
import Testing

@testable import ReverseString

class ReverseStringTests: XCTestCase {
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

@Suite struct ReverseStringTests {

@Test("an empty string")
func testAnEmptyString() {
XCTAssertEqual(reverseString(""), "")
#expect(reverseString("") == "")
}

func testAWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(reverseString("robot"), "tobor")
@Test("a word", .enabled(if: RUNALL))
func testAWord() {
#expect(reverseString("robot") == "tobor")
}

func testACapitalizedWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(reverseString("Ramen"), "nemaR")
@Test("a capitalized word", .enabled(if: RUNALL))
func testACapitalizedWord() {
#expect(reverseString("Ramen") == "nemaR")
}

func testASentenceWithPunctuation() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(reverseString("I'm hungry!"), "!yrgnuh m'I")
@Test("a sentence with punctuation", .enabled(if: RUNALL))
func testASentenceWithPunctuation() {
#expect(reverseString("I'm hungry!") == "!yrgnuh m'I")
}

func testAPalindrome() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(reverseString("racecar"), "racecar")
@Test("a palindrome", .enabled(if: RUNALL))
func testAPalindrome() {
#expect(reverseString("racecar") == "racecar")
}

func testAnEvenSizedWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(reverseString("drawer"), "reward")
@Test("an even-sized word", .enabled(if: RUNALL))
func testAnEvenSizedWord() {
#expect(reverseString("drawer") == "reward")
}
}
6 changes: 3 additions & 3 deletions exercises/practice/rna-transcription/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Instructions

Your task is determine the RNA complement of a given DNA sequence.
Your task is to determine the RNA complement of a given DNA sequence.

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), guanine (**G**) and thymine (**T**).
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), guanine (**G**), and thymine (**T**).

The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), guanine (**G**) and uracil (**U**).
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), guanine (**G**), and uracil (**U**).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

Expand Down
16 changes: 9 additions & 7 deletions exercises/practice/rna-transcription/.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(toRna("{{case.input.dna}}"), "{{case.expected}}")
func test{{case.description |camelCase }}() {
#expect(toRna("{{case.input.dna}}") == "{{case.expected}}")
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/rna-transcription/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