1
exercism fetch swift dominoes

Tests/DominoesTests/DominoesTests.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import XCTest
@testable import Dominoes

class DominoesTests: XCTestCase {

    func testEmptyInputEmptyOutput() {
        let input = [(Int, Int)]()
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testSingletonInputSingletonOutput() {
        let input = [(1, 1)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    func testSingletonThatCantBeChained() {
        let input = [(1, 2)]
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testNoRepeatNumbers() {
        let input = [(1, 2), (3, 1), (2, 3)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    func testCanReverseDominoes() {
        let input = [(1, 2), (1, 3), (2, 3)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    func testInvalidInput() {
        let input = [(1, 2), (4, 1), (2, 3)]
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testDisconnectedSimple() {
        let input = [(1, 1), (2, 2)]
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testDisconnectedDoubleLoop() {
        let input = [(1, 2), (2, 1), (3, 4), (4, 3)]
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testDisconnectedSingleIsolated() {
        let input = [(1, 2), (2, 3), (3, 1), (4, 4)]
        XCTAssertFalse(Dominoes(input).chained)
    }

    func testNeedBacktrack() {
        let input = [(1, 2), (2, 3), (3, 1), (2, 4), (2, 4)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    func testSeparateLoops() {
        let input = [(1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    func testTenElements() {
        let input = [(1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6)]
        XCTAssertTrue(Dominoes(input).chained)
    }

    static var allTests: [(String, (DominoesTests) -> () throws -> Void)] {
        return [
            ("testEmptyInputEmptyOutput", testEmptyInputEmptyOutput),
            ("testSingletonInputSingletonOutput", testSingletonInputSingletonOutput),
            ("testSingletonThatCantBeChained", testSingletonThatCantBeChained),
            ("testNoRepeatNumbers", testNoRepeatNumbers),
            ("testCanReverseDominoes", testCanReverseDominoes),
            ("testInvalidInput", testInvalidInput),
            ("testDisconnectedSimple", testDisconnectedSimple),
            ("testDisconnectedDoubleLoop", testDisconnectedDoubleLoop),
            ("testDisconnectedSingleIsolated", testDisconnectedSingleIsolated),
            ("testNeedBacktrack", testNeedBacktrack),
            ("testSeparateLoops", testSeparateLoops),
            ("testTenElements", testTenElements),
        ]
    }
}

Tests/LinuxMain.swift

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

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