1
exercism fetch swift nth-prime

Tests/LinuxMain.swift

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

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

Tests/NthPrimeTests/NthPrimeTests.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
import XCTest
@testable import NthPrime

class NthPrimeTests: XCTestCase {
    func testFirst() {
        XCTAssertEqual(2, Prime.nth(1))
    }

    func testSecond() {
        XCTAssertEqual(3, Prime.nth(2))
    }

    func testSixthPrime() {
        XCTAssertEqual(13, Prime.nth(6))
    }

    func testBigPrime() {
        XCTAssertEqual(104_743, Prime.nth(10_001))
    }

    func testWeirdCase() {
        XCTAssertNil(Prime.nth(0))
    }

    static var allTests: [(String, (NthPrimeTests) -> () throws -> Void)] {
        return [
            ("testFirst", testFirst),
            ("testSecond", testSecond),
            ("testSixthPrime", testSixthPrime),
            ("testBigPrime", testBigPrime),
            ("testWeirdCase", testWeirdCase),
        ]
    }
}