Skip to content

Commit

Permalink
Update Swift tools version to 6.0 and refactor test cases to use new …
Browse files Browse the repository at this point in the history
…testing framework
  • Loading branch information
meatball133 committed Dec 21, 2024
1 parent 30f8e4c commit 906af5c
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 256 deletions.
16 changes: 9 additions & 7 deletions exercises/practice/roman-numerals/.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({{case.input.number}}.toRomanNumeral(), "{{case.expected}}")
func test{{case.description |camelCase }}() {
#expect({{case.input.number}}.toRomanNumeral() == "{{case.expected}}")
}
{% endfor -%}
}
3 changes: 3 additions & 0 deletions exercises/practice/roman-numerals/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@ description = "3000 is MMM"
[3bc4b41c-c2e6-49d9-9142-420691504336]
description = "3001 is MMMI"

[2f89cad7-73f6-4d1b-857b-0ef531f68b7e]
description = "3888 is MMMDCCCLXXXVIII"

[4e18e96b-5fbb-43df-a91b-9cb511fe0856]
description = "3999 is MMMCMXCIX"
2 changes: 1 addition & 1 deletion exercises/practice/roman-numerals/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,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")
}
}
16 changes: 9 additions & 7 deletions exercises/practice/rotational-cipher/.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(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 -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/rotational-cipher/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,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.")
}
}
Loading

0 comments on commit 906af5c

Please sign in to comment.