Skip to content

Commit cd16ea6

Browse files
authored
[Swift 6]: Update Exercises batch 10 (#794)
* Update Swift tools version to 6.0 and refactor test cases to use new testing framework * Re generate test files
1 parent 72d836e commit cd16ea6

File tree

12 files changed

+422
-402
lines changed

12 files changed

+422
-402
lines changed

exercises/practice/matrix/.meta/template.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import XCTest
1+
import Testing
2+
import Foundation
23
@testable import {{exercise|camelCase}}
3-
class {{exercise|camelCase}}Tests: XCTestCase {
4-
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
54

5+
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
6+
7+
@Suite struct {{exercise|camelCase}}Tests {
68
{% for case in cases %}
79
{% if forloop.first -%}
8-
func test{{case.description |camelCase }}() {
10+
@Test("{{case.description}}")
911
{% else -%}
10-
func test{{case.description |camelCase }}() throws {
11-
try XCTSkipIf(true && !runAll) // change true to false to run this test
12+
@Test("{{case.description}}", .enabled(if: RUNALL))
1213
{% endif -%}
14+
func test{{case.description |camelCase }}() {
1315
let matrix = Matrix("{{case.input.string | inspect}}")
1416
{% if case.property == "row" -%}
15-
XCTAssertEqual({{case.expected}}, matrix.rows[{{case.input.index | minus: 1}}])
17+
#expect({{case.expected}} == matrix.rows[{{case.input.index | minus: 1}}])
1618
{% else -%}
17-
XCTAssertEqual({{case.expected}}, matrix.columns[{{case.input.index | minus: 1}}])
19+
#expect({{case.expected}} == matrix.columns[{{case.input.index | minus: 1}}])
1820
{% endif -%}
1921
}
2022
{% endfor -%}

exercises/practice/matrix/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
1-
import XCTest
1+
import Foundation
2+
import Testing
23

34
@testable import Matrix
45

5-
class MatrixTests: XCTestCase {
6-
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
6+
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
77

8+
@Suite struct MatrixTests {
9+
10+
@Test("extract row from one number matrix")
811
func testExtractRowFromOneNumberMatrix() {
912
let matrix = Matrix("1")
10-
XCTAssertEqual([1], matrix.rows[0])
13+
#expect([1] == matrix.rows[0])
1114
}
1215

13-
func testCanExtractRow() throws {
14-
try XCTSkipIf(true && !runAll) // change true to false to run this test
16+
@Test("can extract row", .enabled(if: RUNALL))
17+
func testCanExtractRow() {
1518
let matrix = Matrix("1 2\n3 4")
16-
XCTAssertEqual([3, 4], matrix.rows[1])
19+
#expect([3, 4] == matrix.rows[1])
1720
}
1821

19-
func testExtractRowWhereNumbersHaveDifferentWidths() throws {
20-
try XCTSkipIf(true && !runAll) // change true to false to run this test
22+
@Test("extract row where numbers have different widths", .enabled(if: RUNALL))
23+
func testExtractRowWhereNumbersHaveDifferentWidths() {
2124
let matrix = Matrix("1 2\n10 20")
22-
XCTAssertEqual([10, 20], matrix.rows[1])
25+
#expect([10, 20] == matrix.rows[1])
2326
}
2427

25-
func testCanExtractRowFromNonSquareMatrixWithNoCorrespondingColumn() throws {
26-
try XCTSkipIf(true && !runAll) // change true to false to run this test
28+
@Test("can extract row from non-square matrix with no corresponding column", .enabled(if: RUNALL))
29+
func testCanExtractRowFromNonSquareMatrixWithNoCorrespondingColumn() {
2730
let matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
28-
XCTAssertEqual([8, 7, 6], matrix.rows[3])
31+
#expect([8, 7, 6] == matrix.rows[3])
2932
}
3033

31-
func testExtractColumnFromOneNumberMatrix() throws {
32-
try XCTSkipIf(true && !runAll) // change true to false to run this test
34+
@Test("extract column from one number matrix", .enabled(if: RUNALL))
35+
func testExtractColumnFromOneNumberMatrix() {
3336
let matrix = Matrix("1")
34-
XCTAssertEqual([1], matrix.columns[0])
37+
#expect([1] == matrix.columns[0])
3538
}
3639

37-
func testCanExtractColumn() throws {
38-
try XCTSkipIf(true && !runAll) // change true to false to run this test
40+
@Test("can extract column", .enabled(if: RUNALL))
41+
func testCanExtractColumn() {
3942
let matrix = Matrix("1 2 3\n4 5 6\n7 8 9")
40-
XCTAssertEqual([3, 6, 9], matrix.columns[2])
43+
#expect([3, 6, 9] == matrix.columns[2])
4144
}
4245

43-
func testCanExtractColumnFromNonSquareMatrixWithNoCorrespondingRow() throws {
44-
try XCTSkipIf(true && !runAll) // change true to false to run this test
46+
@Test("can extract column from non-square matrix with no corresponding row", .enabled(if: RUNALL))
47+
func testCanExtractColumnFromNonSquareMatrixWithNoCorrespondingRow() {
4548
let matrix = Matrix("1 2 3 4\n5 6 7 8\n9 8 7 6")
46-
XCTAssertEqual([4, 8, 6], matrix.columns[3])
49+
#expect([4, 8, 6] == matrix.columns[3])
4750
}
4851

49-
func testExtractColumnWhereNumbersHaveDifferentWidths() throws {
50-
try XCTSkipIf(true && !runAll) // change true to false to run this test
52+
@Test("extract column where numbers have different widths", .enabled(if: RUNALL))
53+
func testExtractColumnWhereNumbersHaveDifferentWidths() {
5154
let matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
52-
XCTAssertEqual([1903, 3, 4], matrix.columns[1])
55+
#expect([1903, 3, 4] == matrix.columns[1])
5356
}
5457
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import XCTest
1+
import Testing
2+
import Foundation
23
@testable import {{exercise|camelCase}}
3-
class {{exercise|camelCase}}Tests: XCTestCase {
4-
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
54

5+
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
6+
7+
@Suite struct {{exercise|camelCase}}Tests {
68
{% for case in cases %}
79
{% if forloop.first -%}
8-
func test{{case.description |camelCase }}() {
10+
@Test("{{case.description}}")
911
{% else -%}
10-
func test{{case.description |camelCase }}() throws {
11-
try XCTSkipIf(true && !runAll) // change true to false to run this test
12+
@Test("{{case.description}}", .enabled(if: RUNALL))
1213
{% endif -%}
14+
func test{{case.description |camelCase }}() {
1315
let meetUp = Meetup(year: {{case.input.year}}, month: {{case.input.month}}, week: "{{case.input.week}}", weekday: "{{case.input.dayofweek}}")
14-
XCTAssertEqual(meetUp.description, "{{case.expected}}")
16+
#expect(meetUp.description == "{{case.expected}}")
1517
}
1618
{% endfor -%}
1719
}

exercises/practice/meetup/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

0 commit comments

Comments
 (0)