-
-
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 cases to use new …
…testing framework
- Loading branch information
1 parent
30f8e4c
commit 998980b
Showing
9 changed files
with
171 additions
and
162 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
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 | ||
|
||
|
25 changes: 11 additions & 14 deletions
25
exercises/practice/two-fer/Tests/TwoFerTests/TwoFerTests.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,21 +1,18 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import TwoFer | ||
|
||
class TwoFerTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
func testNoNameGiven() { | ||
XCTAssertEqual(twoFer(), "One for you, one for me.") | ||
} | ||
@Suite struct TwoFerTests { | ||
|
||
func testANameGiven() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(twoFer(name: "Alice"), "One for Alice, one for me.") | ||
} | ||
@Test("no name given") | ||
func testNoNameGiven() { #expect(twoFer() == "One for you, one for me.") } | ||
|
||
func testAnotherNameGiven() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(twoFer(name: "Bob"), "One for Bob, one for me.") | ||
} | ||
@Test("a name given", .enabled(if: RUNALL)) | ||
func testANameGiven() { #expect(twoFer(name: "Alice") == "One for Alice, one for me.") } | ||
|
||
@Test("another name given", .enabled(if: RUNALL)) | ||
func testAnotherNameGiven() { #expect(twoFer(name: "Bob") == "One for Bob, one for me.") } | ||
} |
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,18 +1,20 @@ | ||
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 words = WordCount(words: "{{case.input.sentence | inspect}}") | ||
let expected = {{case.expected | toStringDictionary}} | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == 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 | ||
|
||
|
89 changes: 46 additions & 43 deletions
89
exercises/practice/word-count/Tests/WordCountTests/WordCountTests.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,108 +1,111 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import WordCount | ||
|
||
class WordCountTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct WordCountTests { | ||
|
||
@Test("count one word") | ||
func testCountOneWord() { | ||
let words = WordCount(words: "word") | ||
let expected = ["word": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testCountOneOfEachWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("count one of each word", .enabled(if: RUNALL)) | ||
func testCountOneOfEachWord() { | ||
let words = WordCount(words: "one of each") | ||
let expected = ["each": 1, "of": 1, "one": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testMultipleOccurrencesOfAWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("multiple occurrences of a word", .enabled(if: RUNALL)) | ||
func testMultipleOccurrencesOfAWord() { | ||
let words = WordCount(words: "one fish two fish red fish blue fish") | ||
let expected = ["blue": 1, "fish": 4, "one": 1, "red": 1, "two": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testHandlesCrampedLists() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("handles cramped lists", .enabled(if: RUNALL)) | ||
func testHandlesCrampedLists() { | ||
let words = WordCount(words: "one,two,three") | ||
let expected = ["one": 1, "three": 1, "two": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testHandlesExpandedLists() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("handles expanded lists", .enabled(if: RUNALL)) | ||
func testHandlesExpandedLists() { | ||
let words = WordCount(words: "one,\ntwo,\nthree") | ||
let expected = ["one": 1, "three": 1, "two": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testIgnorePunctuation() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("ignore punctuation", .enabled(if: RUNALL)) | ||
func testIgnorePunctuation() { | ||
let words = WordCount(words: "car: carpet as java: javascript!!&@$%^&") | ||
let expected = ["as": 1, "car": 1, "carpet": 1, "java": 1, "javascript": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testIncludeNumbers() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("include numbers", .enabled(if: RUNALL)) | ||
func testIncludeNumbers() { | ||
let words = WordCount(words: "testing, 1, 2 testing") | ||
let expected = ["1": 1, "2": 1, "testing": 2] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testNormalizeCase() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("normalize case", .enabled(if: RUNALL)) | ||
func testNormalizeCase() { | ||
let words = WordCount(words: "go Go GO Stop stop") | ||
let expected = ["go": 3, "stop": 2] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testWithApostrophes() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("with apostrophes", .enabled(if: RUNALL)) | ||
func testWithApostrophes() { | ||
let words = WordCount(words: "'First: don't laugh. Then: don't cry. You're getting it.'") | ||
let expected = [ | ||
"cry": 1, "don't": 2, "first": 1, "getting": 1, "it": 1, "laugh": 1, "then": 1, "you're": 1, | ||
] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testWithQuotations() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("with quotations", .enabled(if: RUNALL)) | ||
func testWithQuotations() { | ||
let words = WordCount(words: "Joe can't tell between 'large' and large.") | ||
let expected = ["and": 1, "between": 1, "can't": 1, "joe": 1, "large": 2, "tell": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testSubstringsFromTheBeginning() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("substrings from the beginning", .enabled(if: RUNALL)) | ||
func testSubstringsFromTheBeginning() { | ||
let words = WordCount(words: "Joe can't tell between app, apple and a.") | ||
let expected = [ | ||
"a": 1, "and": 1, "app": 1, "apple": 1, "between": 1, "can't": 1, "joe": 1, "tell": 1, | ||
] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testMultipleSpacesNotDetectedAsAWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("multiple spaces not detected as a word", .enabled(if: RUNALL)) | ||
func testMultipleSpacesNotDetectedAsAWord() { | ||
let words = WordCount(words: " multiple whitespaces") | ||
let expected = ["multiple": 1, "whitespaces": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testAlternatingWordSeparatorsNotDetectedAsAWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("alternating word separators not detected as a word", .enabled(if: RUNALL)) | ||
func testAlternatingWordSeparatorsNotDetectedAsAWord() { | ||
let words = WordCount(words: ",\n,one,\n ,two \n 'three'") | ||
let expected = ["one": 1, "three": 1, "two": 1] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
|
||
func testQuotationForWordWithApostrophe() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("quotation for word with apostrophe", .enabled(if: RUNALL)) | ||
func testQuotationForWordWithApostrophe() { | ||
let words = WordCount(words: "can, can't, 'can't'") | ||
let expected = ["can": 1, "can't": 2] | ||
XCTAssertEqual(words.count(), expected) | ||
#expect(words.count() == expected) | ||
} | ||
} |
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.