-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Swift tools version to 6.0 and refactor test templates for imp…
…roved syntax
- Loading branch information
1 parent
30f8e4c
commit 7829b79
Showing
12 changed files
with
195 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
71 changes: 37 additions & 34 deletions
71
exercises/practice/scrabble-score/Tests/ScrabbleScoreTests/ScrabbleScoreTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -%} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
71 changes: 37 additions & 34 deletions
71
exercises/practice/secret-handshake/Tests/SecretHandshakeTests/SecretHandshakeTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) == []) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
Oops, something went wrong.