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 8 #792

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
18 changes: 10 additions & 8 deletions exercises/practice/isbn-verifier/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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 }}() {
{%- if case.expected -%}
XCTAssertTrue(IsbnVerifier.isValid("{{case.input.isbn}}"))
#expect(IsbnVerifier.isValid("{{case.input.isbn}}"))
{%- else -%}
XCTAssertFalse(IsbnVerifier.isValid("{{case.input.isbn}}"))
#expect(!IsbnVerifier.isValid("{{case.input.isbn}}"))
{%- endif -%}
}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/isbn-verifier/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,101 +1,76 @@
import XCTest
import Foundation
import Testing

@testable import IsbnVerifier

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

func testValidIsbn() {
XCTAssertTrue(IsbnVerifier.isValid("3-598-21508-8"))
}
@Suite struct IsbnVerifierTests {

func testInvalidIsbnCheckDigit() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-21508-9"))
}
@Test("valid isbn")
func testValidIsbn() { #expect(IsbnVerifier.isValid("3-598-21508-8")) }

func testValidIsbnWithACheckDigitOf10() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(IsbnVerifier.isValid("3-598-21507-X"))
}
@Test("invalid isbn check digit", .enabled(if: RUNALL))
func testInvalidIsbnCheckDigit() { #expect(!IsbnVerifier.isValid("3-598-21508-9")) }

func testCheckDigitIsACharacterOtherThanX() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-21507-A"))
}
@Test("valid isbn with a check digit of 10", .enabled(if: RUNALL))
func testValidIsbnWithACheckDigitOf10() { #expect(IsbnVerifier.isValid("3-598-21507-X")) }

func testInvalidCheckDigitInIsbnIsNotTreatedAsZero() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("4-598-21507-B"))
}
@Test("check digit is a character other than X", .enabled(if: RUNALL))
func testCheckDigitIsACharacterOtherThanX() { #expect(!IsbnVerifier.isValid("3-598-21507-A")) }

func testInvalidCharacterInIsbnIsNotTreatedAsZero() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-P1581-X"))
@Test("invalid check digit in isbn is not treated as zero", .enabled(if: RUNALL))
func testInvalidCheckDigitInIsbnIsNotTreatedAsZero() {
#expect(!IsbnVerifier.isValid("4-598-21507-B"))
}

func testXIsOnlyValidAsACheckDigit() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-2X507-9"))
@Test("invalid character in isbn is not treated as zero", .enabled(if: RUNALL))
func testInvalidCharacterInIsbnIsNotTreatedAsZero() {
#expect(!IsbnVerifier.isValid("3-598-P1581-X"))
}

func testValidIsbnWithoutSeparatingDashes() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(IsbnVerifier.isValid("3598215088"))
}
@Test("X is only valid as a check digit", .enabled(if: RUNALL))
func testXIsOnlyValidAsACheckDigit() { #expect(!IsbnVerifier.isValid("3-598-2X507-9")) }

func testIsbnWithoutSeparatingDashesAndXAsCheckDigit() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(IsbnVerifier.isValid("359821507X"))
}
@Test("valid isbn without separating dashes", .enabled(if: RUNALL))
func testValidIsbnWithoutSeparatingDashes() { #expect(IsbnVerifier.isValid("3598215088")) }

func testIsbnWithoutCheckDigitAndDashes() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("359821507"))
@Test("isbn without separating dashes and X as check digit", .enabled(if: RUNALL))
func testIsbnWithoutSeparatingDashesAndXAsCheckDigit() {
#expect(IsbnVerifier.isValid("359821507X"))
}

func testTooLongIsbnAndNoDashes() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3598215078X"))
}
@Test("isbn without check digit and dashes", .enabled(if: RUNALL))
func testIsbnWithoutCheckDigitAndDashes() { #expect(!IsbnVerifier.isValid("359821507")) }

func testTooShortIsbn() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("00"))
}
@Test("too long isbn and no dashes", .enabled(if: RUNALL))
func testTooLongIsbnAndNoDashes() { #expect(!IsbnVerifier.isValid("3598215078X")) }

func testIsbnWithoutCheckDigit() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-21507"))
}
@Test("too short isbn", .enabled(if: RUNALL))
func testTooShortIsbn() { #expect(!IsbnVerifier.isValid("00")) }

func testCheckDigitOfXShouldNotBeUsedFor0() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3-598-21515-X"))
}
@Test("isbn without check digit", .enabled(if: RUNALL))
func testIsbnWithoutCheckDigit() { #expect(!IsbnVerifier.isValid("3-598-21507")) }

func testEmptyIsbn() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid(""))
}
@Test("check digit of X should not be used for 0", .enabled(if: RUNALL))
func testCheckDigitOfXShouldNotBeUsedFor0() { #expect(!IsbnVerifier.isValid("3-598-21515-X")) }

func testInputIs9Characters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("134456729"))
}
@Test("empty isbn", .enabled(if: RUNALL))
func testEmptyIsbn() { #expect(!IsbnVerifier.isValid("")) }

func testInvalidCharactersAreNotIgnoredAfterCheckingLength() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3132P34035"))
}
@Test("input is 9 characters", .enabled(if: RUNALL))
func testInputIs9Characters() { #expect(!IsbnVerifier.isValid("134456729")) }

func testInvalidCharactersAreNotIgnoredBeforeCheckingLength() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("3598P215088"))
@Test("invalid characters are not ignored after checking length", .enabled(if: RUNALL))
func testInvalidCharactersAreNotIgnoredAfterCheckingLength() {
#expect(!IsbnVerifier.isValid("3132P34035"))
}

func testInputIsTooLongButContainsAValidIsbn() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(IsbnVerifier.isValid("98245726788"))
@Test("invalid characters are not ignored before checking length", .enabled(if: RUNALL))
func testInvalidCharactersAreNotIgnoredBeforeCheckingLength() {
#expect(!IsbnVerifier.isValid("3598P215088"))
}

@Test("input is too long but contains a valid isbn", .enabled(if: RUNALL))
func testInputIsTooLongButContainsAValidIsbn() { #expect(!IsbnVerifier.isValid("98245726788")) }
}
18 changes: 10 additions & 8 deletions exercises/practice/isogram/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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 }}() {
{%- if case.expected -%}
XCTAssertTrue(isIsogram("{{case.input.phrase}}"))
#expect(isIsogram("{{case.input.phrase}}"))
{%- else -%}
XCTAssertFalse(isIsogram("{{case.input.phrase}}"))
#expect(!isIsogram("{{case.input.phrase}}"))
{%- endif %}
}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/isogram/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
89 changes: 46 additions & 43 deletions exercises/practice/isogram/Tests/IsogramTests/IsogramTests.swift
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
import XCTest
import Foundation
import Testing

@testable import Isogram

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

@Suite struct IsogramTests {

@Test("empty string")
func testEmptyString() {
XCTAssertTrue(isIsogram(""))
#expect(isIsogram(""))
}

func testIsogramWithOnlyLowerCaseCharacters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isIsogram("isogram"))
@Test("isogram with only lower case characters", .enabled(if: RUNALL))
func testIsogramWithOnlyLowerCaseCharacters() {
#expect(isIsogram("isogram"))
}

func testWordWithOneDuplicatedCharacter() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("eleven"))
@Test("word with one duplicated character", .enabled(if: RUNALL))
func testWordWithOneDuplicatedCharacter() {
#expect(!isIsogram("eleven"))
}

func testWordWithOneDuplicatedCharacterFromTheEndOfTheAlphabet() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("zzyzx"))
@Test("word with one duplicated character from the end of the alphabet", .enabled(if: RUNALL))
func testWordWithOneDuplicatedCharacterFromTheEndOfTheAlphabet() {
#expect(!isIsogram("zzyzx"))
}

func testLongestReportedEnglishIsogram() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isIsogram("subdermatoglyphic"))
@Test("longest reported english isogram", .enabled(if: RUNALL))
func testLongestReportedEnglishIsogram() {
#expect(isIsogram("subdermatoglyphic"))
}

func testWordWithDuplicatedCharacterInMixedCase() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("Alphabet"))
@Test("word with duplicated character in mixed case", .enabled(if: RUNALL))
func testWordWithDuplicatedCharacterInMixedCase() {
#expect(!isIsogram("Alphabet"))
}

func testWordWithDuplicatedCharacterInMixedCaseLowercaseFirst() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("alphAbet"))
@Test("word with duplicated character in mixed case, lowercase first", .enabled(if: RUNALL))
func testWordWithDuplicatedCharacterInMixedCaseLowercaseFirst() {
#expect(!isIsogram("alphAbet"))
}

func testHypotheticalIsogrammicWordWithHyphen() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isIsogram("thumbscrew-japingly"))
@Test("hypothetical isogrammic word with hyphen", .enabled(if: RUNALL))
func testHypotheticalIsogrammicWordWithHyphen() {
#expect(isIsogram("thumbscrew-japingly"))
}

func testHypotheticalWordWithDuplicatedCharacterFollowingHyphen() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("thumbscrew-jappingly"))
@Test("hypothetical word with duplicated character following hyphen", .enabled(if: RUNALL))
func testHypotheticalWordWithDuplicatedCharacterFollowingHyphen() {
#expect(!isIsogram("thumbscrew-jappingly"))
}

func testIsogramWithDuplicatedHyphen() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isIsogram("six-year-old"))
@Test("isogram with duplicated hyphen", .enabled(if: RUNALL))
func testIsogramWithDuplicatedHyphen() {
#expect(isIsogram("six-year-old"))
}

func testMadeUpNameThatIsAnIsogram() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isIsogram("Emily Jung Schwartzkopf"))
@Test("made-up name that is an isogram", .enabled(if: RUNALL))
func testMadeUpNameThatIsAnIsogram() {
#expect(isIsogram("Emily Jung Schwartzkopf"))
}

func testDuplicatedCharacterInTheMiddle() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("accentor"))
@Test("duplicated character in the middle", .enabled(if: RUNALL))
func testDuplicatedCharacterInTheMiddle() {
#expect(!isIsogram("accentor"))
}

func testSameFirstAndLastCharacters() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("angola"))
@Test("same first and last characters", .enabled(if: RUNALL))
func testSameFirstAndLastCharacters() {
#expect(!isIsogram("angola"))
}

func testWordWithDuplicatedCharacterAndWithTwoHyphens() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isIsogram("up-to-date"))
@Test("word with duplicated character and with two hyphens", .enabled(if: RUNALL))
func testWordWithDuplicatedCharacterAndWithTwoHyphens() {
#expect(!isIsogram("up-to-date"))
}
}
22 changes: 12 additions & 10 deletions exercises/practice/kindergarten-garden/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
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 {
{% outer: for case in cases %}
{%- for subCases in case.cases %}
{%- if subCases.cases %}
{%- for subSubCases in subCases.cases %}
func test{{subSubCases.description |camelCase }}() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("{{subSubCases.description}}", .enabled(if: RUNALL))
func test{{subSubCases.description |camelCase }}() {
let garden = Garden("{{subSubCases.input.diagram | inspect}}")
XCTAssertEqual(garden.plantsForChild("{{subSubCases.input.student}}"), {{subSubCases.expected | toEnumArray}})
#expect(garden.plantsForChild("{{subSubCases.input.student}}") == {{subSubCases.expected | toEnumArray}})
}
{% endfor -%}
{%- else %}
{%- if forloop.outer.first and forloop.first %}
func test{{subCases.description |camelCase }}() {
@Test("{{subCases.description}}")
{%- else %}
func test{{subCases.description |camelCase }}() 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 }}() {
let garden = Garden("{{subCases.input.diagram | inspect}}")
XCTAssertEqual(garden.plantsForChild("{{subCases.input.student}}"), {{subCases.expected | toEnumArray}})
#expect(garden.plantsForChild("{{subCases.input.student}}") == {{subCases.expected | toEnumArray}})
}
{%- endif %}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/kindergarten-garden/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