1
exercism fetch swift prime-factors

Tests/LinuxMain.swift

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

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

Tests/PrimeFactorsTests/PrimeFactorsTests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import XCTest
@testable import PrimeFactors

class PrimeFactorsTests: XCTestCase {
    func test1() {
        XCTAssertEqual([], PrimeFactors(1).toArray)
    }

    func test2() {
        XCTAssertEqual([2], PrimeFactors(2).toArray)
    }

    func test3() {
        XCTAssertEqual([3], PrimeFactors(3).toArray)
    }

    func test4() {
        XCTAssertEqual([2, 2], PrimeFactors(4).toArray)
    }

    func test6() {
        XCTAssertEqual([2, 3], PrimeFactors(6).toArray)
    }

    func test8() {
        XCTAssertEqual([2, 2, 2], PrimeFactors(8).toArray)
    }

    func test9() {
        XCTAssertEqual([3, 3], PrimeFactors(9).toArray)
    }

    func test27() {
        XCTAssertEqual([3, 3, 3], PrimeFactors(27).toArray)
    }

    func test625() {
        XCTAssertEqual([5, 5, 5, 5], PrimeFactors(625).toArray)
    }

    func test901255() {
        XCTAssertEqual([5, 17, 23, 461], PrimeFactors(901_255).toArray)
    }

    func test93819012551() {
        XCTAssertEqual([11, 9539, 894_119], PrimeFactors(93_819_012_551).toArray)
    }

    static var allTests: [(String, (PrimeFactorsTests) -> () throws -> Void)] {
        return [
            ("test1", test1),
            ("test2", test2),
            ("test3", test3),
            ("test4", test4),
            ("test6", test6),
            ("test8", test8),
            ("test9", test9),
            ("test27", test27),
            ("test625", test625),
            ("test901255", test901255),
            ("test93819012551", test93819012551),
        ]
    }
}