-
-
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 906af5c
Showing
13 changed files
with
282 additions
and
256 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({{case.input.number}}.toRomanNumeral(), "{{case.expected}}") | ||
func test{{case.description |camelCase }}() { | ||
#expect({{case.input.number}}.toRomanNumeral() == "{{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
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 | ||
|
||
|
166 changes: 87 additions & 79 deletions
166
exercises/practice/roman-numerals/Tests/RomanNumeralsTests/RomanNumeralsTests.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,136 +1,144 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import RomanNumerals | ||
|
||
class RomanNumeralsTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct RomanNumeralsTests { | ||
|
||
@Test("1 is I") | ||
func test1IsI() { | ||
XCTAssertEqual(1.toRomanNumeral(), "I") | ||
#expect(1.toRomanNumeral() == "I") | ||
} | ||
|
||
@Test("2 is II", .enabled(if: RUNALL)) | ||
func test2IsIi() { | ||
#expect(2.toRomanNumeral() == "II") | ||
} | ||
|
||
func test2IsIi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(2.toRomanNumeral(), "II") | ||
@Test("3 is III", .enabled(if: RUNALL)) | ||
func test3IsIii() { | ||
#expect(3.toRomanNumeral() == "III") | ||
} | ||
|
||
func test3IsIii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(3.toRomanNumeral(), "III") | ||
@Test("4 is IV", .enabled(if: RUNALL)) | ||
func test4IsIv() { | ||
#expect(4.toRomanNumeral() == "IV") | ||
} | ||
|
||
func test4IsIv() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(4.toRomanNumeral(), "IV") | ||
@Test("5 is V", .enabled(if: RUNALL)) | ||
func test5IsV() { | ||
#expect(5.toRomanNumeral() == "V") | ||
} | ||
|
||
func test5IsV() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(5.toRomanNumeral(), "V") | ||
@Test("6 is VI", .enabled(if: RUNALL)) | ||
func test6IsVi() { | ||
#expect(6.toRomanNumeral() == "VI") | ||
} | ||
|
||
func test6IsVi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(6.toRomanNumeral(), "VI") | ||
@Test("9 is IX", .enabled(if: RUNALL)) | ||
func test9IsIx() { | ||
#expect(9.toRomanNumeral() == "IX") | ||
} | ||
|
||
func test9IsIx() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(9.toRomanNumeral(), "IX") | ||
@Test("16 is XVI", .enabled(if: RUNALL)) | ||
func test16IsXvi() { | ||
#expect(16.toRomanNumeral() == "XVI") | ||
} | ||
|
||
func test16IsXvi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(16.toRomanNumeral(), "XVI") | ||
@Test("27 is XXVII", .enabled(if: RUNALL)) | ||
func test27IsXxvii() { | ||
#expect(27.toRomanNumeral() == "XXVII") | ||
} | ||
|
||
func test27IsXxvii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(27.toRomanNumeral(), "XXVII") | ||
@Test("48 is XLVIII", .enabled(if: RUNALL)) | ||
func test48IsXlviii() { | ||
#expect(48.toRomanNumeral() == "XLVIII") | ||
} | ||
|
||
func test48IsXlviii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(48.toRomanNumeral(), "XLVIII") | ||
@Test("49 is XLIX", .enabled(if: RUNALL)) | ||
func test49IsXlix() { | ||
#expect(49.toRomanNumeral() == "XLIX") | ||
} | ||
|
||
func test49IsXlix() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(49.toRomanNumeral(), "XLIX") | ||
@Test("59 is LIX", .enabled(if: RUNALL)) | ||
func test59IsLix() { | ||
#expect(59.toRomanNumeral() == "LIX") | ||
} | ||
|
||
func test59IsLix() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(59.toRomanNumeral(), "LIX") | ||
@Test("66 is LXVI", .enabled(if: RUNALL)) | ||
func test66IsLxvi() { | ||
#expect(66.toRomanNumeral() == "LXVI") | ||
} | ||
|
||
func test66IsLxvi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(66.toRomanNumeral(), "LXVI") | ||
@Test("93 is XCIII", .enabled(if: RUNALL)) | ||
func test93IsXciii() { | ||
#expect(93.toRomanNumeral() == "XCIII") | ||
} | ||
|
||
func test93IsXciii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(93.toRomanNumeral(), "XCIII") | ||
@Test("141 is CXLI", .enabled(if: RUNALL)) | ||
func test141IsCxli() { | ||
#expect(141.toRomanNumeral() == "CXLI") | ||
} | ||
|
||
func test141IsCxli() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(141.toRomanNumeral(), "CXLI") | ||
@Test("163 is CLXIII", .enabled(if: RUNALL)) | ||
func test163IsClxiii() { | ||
#expect(163.toRomanNumeral() == "CLXIII") | ||
} | ||
|
||
func test163IsClxiii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(163.toRomanNumeral(), "CLXIII") | ||
@Test("166 is CLXVI", .enabled(if: RUNALL)) | ||
func test166IsClxvi() { | ||
#expect(166.toRomanNumeral() == "CLXVI") | ||
} | ||
|
||
func test166IsClxvi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(166.toRomanNumeral(), "CLXVI") | ||
@Test("402 is CDII", .enabled(if: RUNALL)) | ||
func test402IsCdii() { | ||
#expect(402.toRomanNumeral() == "CDII") | ||
} | ||
|
||
func test402IsCdii() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(402.toRomanNumeral(), "CDII") | ||
@Test("575 is DLXXV", .enabled(if: RUNALL)) | ||
func test575IsDlxxv() { | ||
#expect(575.toRomanNumeral() == "DLXXV") | ||
} | ||
|
||
func test575IsDlxxv() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(575.toRomanNumeral(), "DLXXV") | ||
@Test("666 is DCLXVI", .enabled(if: RUNALL)) | ||
func test666IsDclxvi() { | ||
#expect(666.toRomanNumeral() == "DCLXVI") | ||
} | ||
|
||
func test666IsDclxvi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(666.toRomanNumeral(), "DCLXVI") | ||
@Test("911 is CMXI", .enabled(if: RUNALL)) | ||
func test911IsCmxi() { | ||
#expect(911.toRomanNumeral() == "CMXI") | ||
} | ||
|
||
func test911IsCmxi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(911.toRomanNumeral(), "CMXI") | ||
@Test("1024 is MXXIV", .enabled(if: RUNALL)) | ||
func test1024IsMxxiv() { | ||
#expect(1024.toRomanNumeral() == "MXXIV") | ||
} | ||
|
||
func test1024IsMxxiv() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(1024.toRomanNumeral(), "MXXIV") | ||
@Test("1666 is MDCLXVI", .enabled(if: RUNALL)) | ||
func test1666IsMdclxvi() { | ||
#expect(1666.toRomanNumeral() == "MDCLXVI") | ||
} | ||
|
||
func test1666IsMdclxvi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(1666.toRomanNumeral(), "MDCLXVI") | ||
@Test("3000 is MMM", .enabled(if: RUNALL)) | ||
func test3000IsMmm() { | ||
#expect(3000.toRomanNumeral() == "MMM") | ||
} | ||
|
||
func test3000IsMmm() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(3000.toRomanNumeral(), "MMM") | ||
@Test("3001 is MMMI", .enabled(if: RUNALL)) | ||
func test3001IsMmmi() { | ||
#expect(3001.toRomanNumeral() == "MMMI") | ||
} | ||
|
||
func test3001IsMmmi() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(3001.toRomanNumeral(), "MMMI") | ||
@Test("3888 is MMMDCCCLXXXVIII", .enabled(if: RUNALL)) | ||
func test3888IsMmmdccclxxxviii() { | ||
#expect(3888.toRomanNumeral() == "MMMDCCCLXXXVIII") | ||
} | ||
|
||
func test3999IsMmmcmxcix() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(3999.toRomanNumeral(), "MMMCMXCIX") | ||
@Test("3999 is MMMCMXCIX", .enabled(if: RUNALL)) | ||
func test3999IsMmmcmxcix() { | ||
#expect(3999.toRomanNumeral() == "MMMCMXCIX") | ||
} | ||
} |
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(rotateCipher("{{case.input.text}}", shift: {{case.input.shiftKey}}), "{{case.expected}}") | ||
func test{{case.description |camelCase }}() { | ||
#expect(rotateCipher("{{case.input.text}}", shift: {{case.input.shiftKey}}) == "{{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 | ||
|
||
|
69 changes: 36 additions & 33 deletions
69
exercises/practice/rotational-cipher/Tests/RotationalCipherTests/RotationalCipherTests.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,58 +1,61 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import RotationalCipher | ||
|
||
class RotationalCipherTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct RotationalCipherTests { | ||
|
||
@Test("rotate a by 0, same output as input") | ||
func testRotateABy0SameOutputAsInput() { | ||
XCTAssertEqual(rotateCipher("a", shift: 0), "a") | ||
#expect(rotateCipher("a", shift: 0) == "a") | ||
} | ||
|
||
func testRotateABy1() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("a", shift: 1), "b") | ||
@Test("rotate a by 1", .enabled(if: RUNALL)) | ||
func testRotateABy1() { | ||
#expect(rotateCipher("a", shift: 1) == "b") | ||
} | ||
|
||
func testRotateABy26SameOutputAsInput() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("a", shift: 26), "a") | ||
@Test("rotate a by 26, same output as input", .enabled(if: RUNALL)) | ||
func testRotateABy26SameOutputAsInput() { | ||
#expect(rotateCipher("a", shift: 26) == "a") | ||
} | ||
|
||
func testRotateMBy13() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("m", shift: 13), "z") | ||
@Test("rotate m by 13", .enabled(if: RUNALL)) | ||
func testRotateMBy13() { | ||
#expect(rotateCipher("m", shift: 13) == "z") | ||
} | ||
|
||
func testRotateNBy13WithWrapAroundAlphabet() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("n", shift: 13), "a") | ||
@Test("rotate n by 13 with wrap around alphabet", .enabled(if: RUNALL)) | ||
func testRotateNBy13WithWrapAroundAlphabet() { | ||
#expect(rotateCipher("n", shift: 13) == "a") | ||
} | ||
|
||
func testRotateCapitalLetters() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("OMG", shift: 5), "TRL") | ||
@Test("rotate capital letters", .enabled(if: RUNALL)) | ||
func testRotateCapitalLetters() { | ||
#expect(rotateCipher("OMG", shift: 5) == "TRL") | ||
} | ||
|
||
func testRotateSpaces() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("O M G", shift: 5), "T R L") | ||
@Test("rotate spaces", .enabled(if: RUNALL)) | ||
func testRotateSpaces() { | ||
#expect(rotateCipher("O M G", shift: 5) == "T R L") | ||
} | ||
|
||
func testRotateNumbers() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("Testing 1 2 3 testing", shift: 4), "Xiwxmrk 1 2 3 xiwxmrk") | ||
@Test("rotate numbers", .enabled(if: RUNALL)) | ||
func testRotateNumbers() { | ||
#expect(rotateCipher("Testing 1 2 3 testing", shift: 4) == "Xiwxmrk 1 2 3 xiwxmrk") | ||
} | ||
|
||
func testRotatePunctuation() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(rotateCipher("Let's eat, Grandma!", shift: 21), "Gzo'n zvo, Bmviyhv!") | ||
@Test("rotate punctuation", .enabled(if: RUNALL)) | ||
func testRotatePunctuation() { | ||
#expect(rotateCipher("Let's eat, Grandma!", shift: 21) == "Gzo'n zvo, Bmviyhv!") | ||
} | ||
|
||
func testRotateAllLetters() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
rotateCipher("The quick brown fox jumps over the lazy dog.", shift: 13), | ||
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") | ||
@Test("rotate all letters", .enabled(if: RUNALL)) | ||
func testRotateAllLetters() { | ||
#expect( | ||
rotateCipher("The quick brown fox jumps over the lazy dog.", shift: 13) | ||
== "Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") | ||
} | ||
} |
Oops, something went wrong.