1
exercism fetch swift matrix

Tests/LinuxMain.swift

1
2
3
4
5
6
import XCTest
@testable import MatrixTests

XCTMain([
    testCase(MatrixTests.allTests),
    ])

Tests/MatrixTests/MatrixTests.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import XCTest
@testable import Matrix

class MatrixTests: XCTestCase {
    func testExtractARow() {
        let matrix = Matrix("1 2\n10 20")
        XCTAssertEqual([1, 2], matrix.rows[0])
    }

    func testExtractSameRowAgain() {
        let matrix = Matrix("9 7\n8 6")
        XCTAssertEqual([9, 7], matrix.rows[0])
    }

    func testExtractOtherRow() {
        let matrix = Matrix("9 8 7\n19 18 17")
        XCTAssertEqual([19, 18, 17], matrix.rows[1])
    }

    func testExtractOtherRowAgain() {
        let matrix = Matrix("1 4 9\n16 25 36")
        XCTAssertEqual([16, 25, 36], matrix.rows[1])
    }

    func testExtractAColumn() {
        let matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
        XCTAssertEqual([1, 4, 7, 8], matrix.columns[0])
    }

    func testExtractAnotherColumn() {
        let matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
        XCTAssertEqual([1903, 3, 4], matrix.columns[1])
    }

    static var allTests: [(String, (MatrixTests) -> () throws -> Void)] {
        return [
            ("testExtractARow", testExtractARow),
            ("testExtractSameRowAgain", testExtractSameRowAgain),
            ("testExtractOtherRow", testExtractOtherRow),
            ("testExtractOtherRowAgain", testExtractOtherRowAgain),
            ("testExtractAColumn", testExtractAColumn),
            ("testExtractAnotherColumn", testExtractAnotherColumn),
        ]
    }
}