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 10 #794

Draft
wants to merge 3 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
18 changes: 10 additions & 8 deletions exercises/practice/matrix/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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 matrix = Matrix("{{case.input.string | inspect}}")
{% if case.property == "row" -%}
XCTAssertEqual({{case.expected}}, matrix.rows[{{case.input.index | minus: 1}}])
#expect({{case.expected}} == matrix.rows[{{case.input.index | minus: 1}}])
{% else -%}
XCTAssertEqual({{case.expected}}, matrix.columns[{{case.input.index | minus: 1}}])
#expect({{case.expected}} == matrix.columns[{{case.input.index | minus: 1}}])
{% endif -%}
}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/matrix/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
53 changes: 28 additions & 25 deletions exercises/practice/matrix/Tests/MatrixTests/MatrixTests.swift
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
import XCTest
import Foundation
import Testing

@testable import Matrix

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

@Suite struct MatrixTests {

@Test("extract row from one number matrix")
func testExtractRowFromOneNumberMatrix() {
let matrix = Matrix("1")
XCTAssertEqual([1], matrix.rows[0])
#expect([1] == matrix.rows[0])
}

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

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

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

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

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

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

func testExtractColumnWhereNumbersHaveDifferentWidths() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("extract column where numbers have different widths", .enabled(if: RUNALL))
func testExtractColumnWhereNumbersHaveDifferentWidths() {
let matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
XCTAssertEqual([1903, 3, 4], matrix.columns[1])
#expect([1903, 3, 4] == matrix.columns[1])
}
}
16 changes: 9 additions & 7 deletions exercises/practice/meetup/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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 meetUp = Meetup(year: {{case.input.year}}, month: {{case.input.month}}, week: "{{case.input.week}}", weekday: "{{case.input.dayofweek}}")
XCTAssertEqual(meetUp.description, "{{case.expected}}")
#expect(meetUp.description == "{{case.expected}}")
}
{% endfor -%}
}
2 changes: 1 addition & 1 deletion exercises/practice/meetup/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