Skip to content

[Swift 6]: Update Exercises batch 16 #800

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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/scrabble-score/.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(score("{{case.input.word}}"), {{case.expected}})
func test{{case.description |camelCase }}() {
#expect(score("{{case.input.word}}") == {{case.expected}})
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/scrabble-score/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,61 +1,64 @@
import XCTest
import Foundation
import Testing

@testable import ScrabbleScore

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

@Suite struct ScrabbleScoreTests {

@Test("lowercase letter")
func testLowercaseLetter() {
XCTAssertEqual(score("a"), 1)
#expect(score("a") == 1)
}

func testUppercaseLetter() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("A"), 1)
@Test("uppercase letter", .enabled(if: RUNALL))
func testUppercaseLetter() {
#expect(score("A") == 1)
}

func testValuableLetter() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("f"), 4)
@Test("valuable letter", .enabled(if: RUNALL))
func testValuableLetter() {
#expect(score("f") == 4)
}

func testShortWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("at"), 2)
@Test("short word", .enabled(if: RUNALL))
func testShortWord() {
#expect(score("at") == 2)
}

func testShortValuableWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("zoo"), 12)
@Test("short, valuable word", .enabled(if: RUNALL))
func testShortValuableWord() {
#expect(score("zoo") == 12)
}

func testMediumWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("street"), 6)
@Test("medium word", .enabled(if: RUNALL))
func testMediumWord() {
#expect(score("street") == 6)
}

func testMediumValuableWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("quirky"), 22)
@Test("medium, valuable word", .enabled(if: RUNALL))
func testMediumValuableWord() {
#expect(score("quirky") == 22)
}

func testLongMixedCaseWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("OxyphenButazone"), 41)
@Test("long, mixed-case word", .enabled(if: RUNALL))
func testLongMixedCaseWord() {
#expect(score("OxyphenButazone") == 41)
}

func testEnglishLikeWord() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("pinata"), 8)
@Test("english-like word", .enabled(if: RUNALL))
func testEnglishLikeWord() {
#expect(score("pinata") == 8)
}

func testEmptyInput() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score(""), 0)
@Test("empty input", .enabled(if: RUNALL))
func testEmptyInput() {
#expect(score("") == 0)
}

func testEntireAlphabetAvailable() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(score("abcdefghijklmnopqrstuvwxyz"), 87)
@Test("entire alphabet available", .enabled(if: RUNALL))
func testEntireAlphabetAvailable() {
#expect(score("abcdefghijklmnopqrstuvwxyz") == 87)
}
}
16 changes: 9 additions & 7 deletions exercises/practice/secret-handshake/.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(commands(number: {{case.input.number}}), {{case.expected | toStringArray}})
func test{{case.description |camelCase }}() {
#expect(commands(number: {{case.input.number}}) == {{case.expected | toStringArray}})
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/secret-handshake/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,61 +1,64 @@
import XCTest
import Foundation
import Testing

@testable import SecretHandshake

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

@Suite struct SecretHandshakeTests {

@Test("wink for 1")
func testWinkFor1() {
XCTAssertEqual(commands(number: 1), ["wink"])
#expect(commands(number: 1) == ["wink"])
}

func testDoubleBlinkFor10() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 2), ["double blink"])
@Test("double blink for 10", .enabled(if: RUNALL))
func testDoubleBlinkFor10() {
#expect(commands(number: 2) == ["double blink"])
}

func testCloseYourEyesFor100() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 4), ["close your eyes"])
@Test("close your eyes for 100", .enabled(if: RUNALL))
func testCloseYourEyesFor100() {
#expect(commands(number: 4) == ["close your eyes"])
}

func testJumpFor1000() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 8), ["jump"])
@Test("jump for 1000", .enabled(if: RUNALL))
func testJumpFor1000() {
#expect(commands(number: 8) == ["jump"])
}

func testCombineTwoActions() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 3), ["wink", "double blink"])
@Test("combine two actions", .enabled(if: RUNALL))
func testCombineTwoActions() {
#expect(commands(number: 3) == ["wink", "double blink"])
}

func testReverseTwoActions() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 19), ["double blink", "wink"])
@Test("reverse two actions", .enabled(if: RUNALL))
func testReverseTwoActions() {
#expect(commands(number: 19) == ["double blink", "wink"])
}

func testReversingOneActionGivesTheSameAction() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 24), ["jump"])
@Test("reversing one action gives the same action", .enabled(if: RUNALL))
func testReversingOneActionGivesTheSameAction() {
#expect(commands(number: 24) == ["jump"])
}

func testReversingNoActionsStillGivesNoActions() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 16), [])
@Test("reversing no actions still gives no actions", .enabled(if: RUNALL))
func testReversingNoActionsStillGivesNoActions() {
#expect(commands(number: 16) == [])
}

func testAllPossibleActions() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 15), ["wink", "double blink", "close your eyes", "jump"])
@Test("all possible actions", .enabled(if: RUNALL))
func testAllPossibleActions() {
#expect(commands(number: 15) == ["wink", "double blink", "close your eyes", "jump"])
}

func testReverseAllPossibleActions() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 31), ["jump", "close your eyes", "double blink", "wink"])
@Test("reverse all possible actions", .enabled(if: RUNALL))
func testReverseAllPossibleActions() {
#expect(commands(number: 31) == ["jump", "close your eyes", "double blink", "wink"])
}

func testDoNothingForZero() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertEqual(commands(number: 0), [])
@Test("do nothing for zero", .enabled(if: RUNALL))
func testDoNothingForZero() {
#expect(commands(number: 0) == [])
}
}
27 changes: 15 additions & 12 deletions exercises/practice/series/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
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 series = Series("{{case.input.series}}")
{%- if case.expected.error %}
XCTAssertThrowsError(try series.slice({{case.input.sliceLength}})) { error in
#expect(throws:
{% if case.expected.error == "slice length cannot be greater than series length" -%}
XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthLongerThanSeries)
SeriesError.sliceLengthLongerThanSeries
{%- elif case.expected.error == "series cannot be empty" -%}
XCTAssertEqual(error as? SeriesError, SeriesError.emptySeries)
SeriesError.emptySeries
{%- elif case.expected.error == "slice length cannot be negative" or case.expected.error == "slice length cannot be zero" -%}
XCTAssertEqual(error as? SeriesError, SeriesError.sliceLengthZeroOrLess)
SeriesError.sliceLengthZeroOrLess
{%- endif %}
}
)
{try series.slice({{case.input.sliceLength}})}
{%- else %}
XCTAssertEqual(try! series.slice({{case.input.sliceLength}}), {{case.expected | toStringArray}})
#expect(try! series.slice({{case.input.sliceLength}}) == {{case.expected | toStringArray}})
{%- endif %}
}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/series/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