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 3 #787

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
26 changes: 14 additions & 12 deletions exercises/practice/bob/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import XCTest
@testable import Bob
class BobTests: XCTestCase {
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

import Testing
import Foundation
@testable import {{exercise|camelCase}}

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 }}() {
{% else -%}
func test{{case.description | camelCase }}() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
{% endif -%}
XCTAssertEqual("{{case.expected}}", Bob.response("{{case.input.heyBob | inspect}}"))
{% if forloop.first -%}
@Test("{{case.description}}")
{% else -%}
@Test("{{case.description}}", .enabled(if: RUNALL))
{% endif -%}
func test{{case.description |camelCase }}() {
#expect("{{case.expected}}" == Bob.response("{{case.input.heyBob | inspect}}"))
}
{% endfor %}
}
5 changes: 5 additions & 0 deletions exercises/practice/bob/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ description = "alternate silence"

[66953780-165b-4e7e-8ce3-4bcb80b6385a]
description = "multiple line question"
include = false

[5371ef75-d9ea-4103-bcfa-2da973ddec1b]
description = "starting with whitespace"
Expand All @@ -83,3 +84,7 @@ description = "other whitespace"

[12983553-8601-46a8-92fa-fcaa3bc4a2a0]
description = "non-question ending with whitespace"

[2c7278ac-f955-4eb4-bf8f-e33eb4116a15]
description = "multiple line question"
reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a"
2 changes: 1 addition & 1 deletion exercises/practice/bob/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
157 changes: 79 additions & 78 deletions exercises/practice/bob/Tests/BobTests/BobTests.swift
Original file line number Diff line number Diff line change
@@ -1,134 +1,135 @@
import XCTest
import Foundation
import Testing

@testable import Bob

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

@Suite struct BobTests {

@Test("stating something")
func testStatingSomething() {
XCTAssertEqual("Whatever.", Bob.response("Tom-ay-to, tom-aaaah-to."))
#expect("Whatever." == Bob.response("Tom-ay-to, tom-aaaah-to."))
}

func testShouting() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whoa, chill out!", Bob.response("WATCH OUT!"))
@Test("shouting", .enabled(if: RUNALL))
func testShouting() {
#expect("Whoa, chill out!" == Bob.response("WATCH OUT!"))
}

func testShoutingGibberish() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whoa, chill out!", Bob.response("FCECDFCAAB"))
@Test("shouting gibberish", .enabled(if: RUNALL))
func testShoutingGibberish() {
#expect("Whoa, chill out!" == Bob.response("FCECDFCAAB"))
}

func testAskingAQuestion() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("Does this cryogenic chamber make me look fat?"))
@Test("asking a question", .enabled(if: RUNALL))
func testAskingAQuestion() {
#expect("Sure." == Bob.response("Does this cryogenic chamber make me look fat?"))
}

func testAskingANumericQuestion() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("You are, what, like 15?"))
@Test("asking a numeric question", .enabled(if: RUNALL))
func testAskingANumericQuestion() {
#expect("Sure." == Bob.response("You are, what, like 15?"))
}

func testAskingGibberish() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("fffbbcbeab?"))
@Test("asking gibberish", .enabled(if: RUNALL))
func testAskingGibberish() {
#expect("Sure." == Bob.response("fffbbcbeab?"))
}

func testTalkingForcefully() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response("Hi there!"))
@Test("talking forcefully", .enabled(if: RUNALL))
func testTalkingForcefully() {
#expect("Whatever." == Bob.response("Hi there!"))
}

func testUsingAcronymsInRegularSpeech() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response("It's OK if you don't want to go work for NASA."))
@Test("using acronyms in regular speech", .enabled(if: RUNALL))
func testUsingAcronymsInRegularSpeech() {
#expect("Whatever." == Bob.response("It's OK if you don't want to go work for NASA."))
}

func testForcefulQuestion() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Calm down, I know what I'm doing!", Bob.response("WHAT'S GOING ON?"))
@Test("forceful question", .enabled(if: RUNALL))
func testForcefulQuestion() {
#expect("Calm down, I know what I'm doing!" == Bob.response("WHAT'S GOING ON?"))
}

func testShoutingNumbers() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whoa, chill out!", Bob.response("1, 2, 3 GO!"))
@Test("shouting numbers", .enabled(if: RUNALL))
func testShoutingNumbers() {
#expect("Whoa, chill out!" == Bob.response("1, 2, 3 GO!"))
}

func testNoLetters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response("1, 2, 3"))
@Test("no letters", .enabled(if: RUNALL))
func testNoLetters() {
#expect("Whatever." == Bob.response("1, 2, 3"))
}

func testQuestionWithNoLetters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("4?"))
@Test("question with no letters", .enabled(if: RUNALL))
func testQuestionWithNoLetters() {
#expect("Sure." == Bob.response("4?"))
}

func testShoutingWithSpecialCharacters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(
"Whoa, chill out!", Bob.response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))
@Test("shouting with special characters", .enabled(if: RUNALL))
func testShoutingWithSpecialCharacters() {
#expect("Whoa, chill out!" == Bob.response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))
}

func testShoutingWithNoExclamationMark() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whoa, chill out!", Bob.response("I HATE THE DENTIST"))
@Test("shouting with no exclamation mark", .enabled(if: RUNALL))
func testShoutingWithNoExclamationMark() {
#expect("Whoa, chill out!" == Bob.response("I HATE THE DENTIST"))
}

func testStatementContainingQuestionMark() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response("Ending with ? means a question."))
@Test("statement containing question mark", .enabled(if: RUNALL))
func testStatementContainingQuestionMark() {
#expect("Whatever." == Bob.response("Ending with ? means a question."))
}

func testNonLettersWithQuestion() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response(":) ?"))
@Test("non-letters with question", .enabled(if: RUNALL))
func testNonLettersWithQuestion() {
#expect("Sure." == Bob.response(":) ?"))
}

func testPrattlingOn() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("Wait! Hang on. Are you going to be OK?"))
@Test("prattling on", .enabled(if: RUNALL))
func testPrattlingOn() {
#expect("Sure." == Bob.response("Wait! Hang on. Are you going to be OK?"))
}

func testSilence() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Fine. Be that way!", Bob.response(""))
@Test("silence", .enabled(if: RUNALL))
func testSilence() {
#expect("Fine. Be that way!" == Bob.response(""))
}

func testProlongedSilence() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Fine. Be that way!", Bob.response(" "))
@Test("prolonged silence", .enabled(if: RUNALL))
func testProlongedSilence() {
#expect("Fine. Be that way!" == Bob.response(" "))
}

func testAlternateSilence() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Fine. Be that way!", Bob.response("\t\t\t\t\t\t\t\t\t\t"))
@Test("alternate silence", .enabled(if: RUNALL))
func testAlternateSilence() {
#expect("Fine. Be that way!" == Bob.response("\t\t\t\t\t\t\t\t\t\t"))
}

func testMultipleLineQuestion() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(
"Whatever.", Bob.response("\nDoes this cryogenic chamber make me look fat?\nNo."))
@Test("starting with whitespace", .enabled(if: RUNALL))
func testStartingWithWhitespace() {
#expect("Whatever." == Bob.response(" hmmmmmmm..."))
}

func testStartingWithWhitespace() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response(" hmmmmmmm..."))
@Test("ending with whitespace", .enabled(if: RUNALL))
func testEndingWithWhitespace() {
#expect("Sure." == Bob.response("Okay if like my spacebar quite a bit? "))
}

func testEndingWithWhitespace() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Sure.", Bob.response("Okay if like my spacebar quite a bit? "))
@Test("other whitespace", .enabled(if: RUNALL))
func testOtherWhitespace() {
#expect("Fine. Be that way!" == Bob.response("\n\r \t"))
}

func testOtherWhitespace() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Fine. Be that way!", Bob.response("\n\r \t"))
@Test("non-question ending with whitespace", .enabled(if: RUNALL))
func testNonQuestionEndingWithWhitespace() {
#expect("Whatever." == Bob.response("This is a statement ending with whitespace "))
}

func testNonQuestionEndingWithWhitespace() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual("Whatever.", Bob.response("This is a statement ending with whitespace "))
@Test("multiple line question", .enabled(if: RUNALL))
func testMultipleLineQuestion() {
#expect("Sure." == Bob.response("\nDoes this cryogenic chamber make\n me look fat?"))
}

}
28 changes: 15 additions & 13 deletions exercises/practice/bottle-song/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
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 {
{% outerOuter: for case in cases %}
{%- outer: for subCases in case.cases %}
{%- if subCases.cases %}
{%- for subSubCases in subCases.cases %}
{%- if forloop.outerOuter.first and forloop.outer.first and forloop.first %}
func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() {
{%- else %}
func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
{%- endif %}
@Test("{{subSubCases.description}}")
{%- else %}
@Test("{{subSubCases.description}}", .enabled(if: RUNALL))
{%- endif %}
func test{{subSubCases.description |camelCase }}{{ forloop.outer.counter }}() {
let bottleSong = BottleSong(bottles: {{subSubCases.input.startBottles}})
let expected = {{subSubCases.expected | toStringArray }}
XCTAssertEqual(bottleSong.song(takedown: {{subSubCases.input.takeDown}}), expected)
#expect(bottleSong.song(takedown: {{subSubCases.input.takeDown}}) == expected)
}
{% endfor -%}
{%- else %}
{%- if forloop.outerOuter.first and forloop.outer.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 bottleSong = BottleSong(bottles: {{subCases.input.startBottles}})
let expected = {{subCases.expected | toStringArray }}
XCTAssertEqual(bottleSong.song(takedown: {{subCases.input.takeDown}}), expected)
#expect(bottleSong.song(takedown: {{subCases.input.takeDown}}) == expected)
}
{%- endif %}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bottle-song/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