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 18 #802

Draft
wants to merge 2 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
19 changes: 11 additions & 8 deletions exercises/practice/tournament/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,26 +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 {
private var tournament: Tournament!

override func setUp() {
init() {
tournament = Tournament()
}

{% 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 }}() {
{% for row in case.input.rows -%}
tournament.addMatch("{{row}}")
{% endfor -%}
let expected = {{case.expected | toStringArray }}
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/tournament/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,91 +1,93 @@
import XCTest
import Foundation
import Testing

@testable import Tournament

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

@Suite struct TournamentTests {
private var tournament: Tournament!

override func setUp() {
init() {
tournament = Tournament()
}

@Test("just the header if no input")
func testJustTheHeaderIfNoInput() {
let expected = ["Team | MP | W | D | L | P"]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testAWinIsThreePointsALossIsZeroPoints() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("a win is three points, a loss is zero points", .enabled(if: RUNALL))
func testAWinIsThreePointsALossIsZeroPoints() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
let expected = [
"Team | MP | W | D | L | P",
"Allegoric Alaskans | 1 | 1 | 0 | 0 | 3",
"Blithering Badgers | 1 | 0 | 0 | 1 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testAWinCanAlsoBeExpressedAsALoss() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("a win can also be expressed as a loss", .enabled(if: RUNALL))
func testAWinCanAlsoBeExpressedAsALoss() {
tournament.addMatch("Blithering Badgers;Allegoric Alaskans;loss")
let expected = [
"Team | MP | W | D | L | P",
"Allegoric Alaskans | 1 | 1 | 0 | 0 | 3",
"Blithering Badgers | 1 | 0 | 0 | 1 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testADifferentTeamCanWin() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("a different team can win", .enabled(if: RUNALL))
func testADifferentTeamCanWin() {
tournament.addMatch("Blithering Badgers;Allegoric Alaskans;win")
let expected = [
"Team | MP | W | D | L | P",
"Blithering Badgers | 1 | 1 | 0 | 0 | 3",
"Allegoric Alaskans | 1 | 0 | 0 | 1 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testADrawIsOnePointEach() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("a draw is one point each", .enabled(if: RUNALL))
func testADrawIsOnePointEach() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;draw")
let expected = [
"Team | MP | W | D | L | P",
"Allegoric Alaskans | 1 | 0 | 1 | 0 | 1",
"Blithering Badgers | 1 | 0 | 1 | 0 | 1",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testThereCanBeMoreThanOneMatch() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("There can be more than one match", .enabled(if: RUNALL))
func testThereCanBeMoreThanOneMatch() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
let expected = [
"Team | MP | W | D | L | P",
"Allegoric Alaskans | 2 | 2 | 0 | 0 | 6",
"Blithering Badgers | 2 | 0 | 0 | 2 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testThereCanBeMoreThanOneWinner() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("There can be more than one winner", .enabled(if: RUNALL))
func testThereCanBeMoreThanOneWinner() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;loss")
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
let expected = [
"Team | MP | W | D | L | P",
"Allegoric Alaskans | 2 | 1 | 0 | 1 | 3",
"Blithering Badgers | 2 | 1 | 0 | 1 | 3",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testThereCanBeMoreThanTwoTeams() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("There can be more than two teams", .enabled(if: RUNALL))
func testThereCanBeMoreThanTwoTeams() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
tournament.addMatch("Blithering Badgers;Courageous Californians;win")
tournament.addMatch("Courageous Californians;Allegoric Alaskans;loss")
Expand All @@ -95,11 +97,11 @@ class TournamentTests: XCTestCase {
"Blithering Badgers | 2 | 1 | 0 | 1 | 3",
"Courageous Californians | 2 | 0 | 0 | 2 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testTypicalInput() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("typical input", .enabled(if: RUNALL))
func testTypicalInput() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
tournament.addMatch("Devastating Donkeys;Courageous Californians;draw")
tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;win")
Expand All @@ -113,11 +115,11 @@ class TournamentTests: XCTestCase {
"Blithering Badgers | 3 | 1 | 0 | 2 | 3",
"Courageous Californians | 3 | 0 | 1 | 2 | 1",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testIncompleteCompetitionNotAllPairsHavePlayed() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("incomplete competition (not all pairs have played)", .enabled(if: RUNALL))
func testIncompleteCompetitionNotAllPairsHavePlayed() {
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;loss")
tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;loss")
tournament.addMatch("Courageous Californians;Blithering Badgers;draw")
Expand All @@ -129,11 +131,11 @@ class TournamentTests: XCTestCase {
"Courageous Californians | 2 | 0 | 1 | 1 | 1",
"Devastating Donkeys | 1 | 0 | 0 | 1 | 0",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testTiesBrokenAlphabetically() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("ties broken alphabetically", .enabled(if: RUNALL))
func testTiesBrokenAlphabetically() {
tournament.addMatch("Courageous Californians;Devastating Donkeys;win")
tournament.addMatch("Allegoric Alaskans;Blithering Badgers;win")
tournament.addMatch("Devastating Donkeys;Allegoric Alaskans;loss")
Expand All @@ -147,11 +149,11 @@ class TournamentTests: XCTestCase {
"Blithering Badgers | 3 | 0 | 1 | 2 | 1",
"Devastating Donkeys | 3 | 0 | 1 | 2 | 1",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}

func testEnsurePointsSortedNumerically() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("ensure points sorted numerically", .enabled(if: RUNALL))
func testEnsurePointsSortedNumerically() {
tournament.addMatch("Devastating Donkeys;Blithering Badgers;win")
tournament.addMatch("Devastating Donkeys;Blithering Badgers;win")
tournament.addMatch("Devastating Donkeys;Blithering Badgers;win")
Expand All @@ -162,6 +164,6 @@ class TournamentTests: XCTestCase {
"Devastating Donkeys | 5 | 4 | 0 | 1 | 12",
"Blithering Badgers | 5 | 1 | 0 | 4 | 3",
]
XCTAssertEqual(tournament.tally(), expected)
#expect(tournament.tally() == expected)
}
}
16 changes: 9 additions & 7 deletions exercises/practice/transpose/.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(Transpose.transpose({{case.input.lines | toStringArray }}), {{case.expected | toStringArray}})
func test{{case.description |camelCase }}() {
#expect(Transpose.transpose({{case.input.lines | toStringArray }}) == {{case.expected | toStringArray}})
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/transpose/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