Sha256: 2ae8fc4a658c68b90c7d1087542a6a81e9ec0a3481a81b166055f9d065ca4683

Contents?: true

Size: 1.63 KB

Versions: 325

Compression:

Stored size: 1.63 KB

Contents

import XCTest
@testable import PascalsTriangle

private extension XCTest {
    func XCTAssertEqualMultiArray(_ aArray1: [[Int]], _ aArray2: [[Int]]) {
        XCTAssertEqual(Array(aArray1.joined()), Array(aArray2.joined()))
    }
}

class PascalsTriangleTests: XCTestCase {
    func testOneRow() {
        let triangle = PascalsTriangle(1)
        XCTAssertEqualMultiArray([[1]], triangle.rows)
    }

    func testTwoRows() {
        let triangle = PascalsTriangle(2)
        XCTAssertEqualMultiArray([[1], [1, 1]], triangle.rows)
    }

    func testThreeRows() {
        let triangle = PascalsTriangle(3)
        XCTAssertEqualMultiArray([[1], [1, 1], [1, 2, 1]], triangle.rows)
    }

    func testFourthRow() {
        let triangle = PascalsTriangle(4)
        XCTAssertEqual([1, 3, 3, 1], triangle.rows.last!)
    }

    func testFifthRow() {
        let triangle = PascalsTriangle(5)
        XCTAssertEqual([1, 4, 6, 4, 1], triangle.rows.last!)
    }

    func testTwentiethRow() {
        let triangle = PascalsTriangle(20)
        let expected = [
            1, 19, 171, 969, 3876, 11_628, 27_132, 50_388, 75_582, 92_378, 92_378,
            75_582, 50_388, 27_132, 11_628, 3876, 969, 171, 19, 1
        ]
        XCTAssertEqual(expected, triangle.rows.last!)
    }

    static var allTests: [(String, (PascalsTriangleTests) -> () throws -> Void)] {
        return [
            ("testOneRow", testOneRow),
            ("testTwoRows", testTwoRows),
            ("testThreeRows", testThreeRows),
            ("testFourthRow", testFourthRow),
            ("testFifthRow", testFifthRow),
            ("testTwentiethRow", testTwentiethRow),
        ]
    }
}

Version data entries

325 entries across 325 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.138 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.137 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.136 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.135 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.134 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.133 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.132 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.131 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.130 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.129 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.128 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.127 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.126 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.125 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.124 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.123 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.122 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.121 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
trackler-2.2.1.120 tracks/swift/exercises/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift